Академический Документы
Профессиональный Документы
Культура Документы
6. Check if the first number (argument) is a prime number (For example, if the input is 23
and 10, then output should be 1 (or yes)).
Code for the above functionalities is given below (.x IDL file, client.c, and server.c files). Your
task is to add the following additional functionalities into the given program:
7. Check if both the input arguments are even or both are odd. Display “Yes” if both are
either even or both are odd, else display “No”.
8. Pl. ensure proper error checks like, if the input arguments are not integers then the
server should respond back with an error message as “arguments are not of valid type”.
Code:
cal.x fle:
struct variable
{
int x; int y; int ans; int choice;
};
program calc_prg
{
version calc_version
{
int calc(variable)=1;
}=1;
}=0x32345676;
cal_client.c file:
#include "cal.h"
if (argc < 2) {
printf ("usage: %s server_host\n", argv[0]);
exit (1);
}
host = argv[1];
calc_prg_1 (host);
exit (0);
}
cal_server.c file:
#include "cal.h"
int isprime(int a)
{
int i;
for(i=2;i<=a/2;i++)
{if(a%i==0)
{break;}}
if(i==a/2+1)
{
printf("\nYES\n");
return 1;
}
else
{
printf("\nNO\n");
return 0;
}
}
case 1:
{
result=(argp->x)+(argp->y);
break;
}
case 2:
{
result=(argp->x)*(argp->y);
break;
}
case 3:
{
result=(argp->x)-(argp->y);
break;
}
case 4:
{
result=(argp->x)/(argp->y);
break;
}
case 5:
{
result=(argp->x)%(argp->y);
break;
}
case 6:
{
result=isprime(argp->x);
break;
}
}
return &result;
}
Task 2 (4 Marks): Lamport proposed a scheme to order the events in a distributed system by
using logical clocks. Due to the absence of synchronized clocks and hence global time in a
distributed system, the order in which events occur at two different machines is impossible to
be determined based on the local time at which they occurred.
a) Clock Ci is implemented between any two events of the same process as Ci = Ci + d (d >0)
b) If event a is a send message by process Pi and the same is received by process Pj, then tm =
Ci (a), and Cj = max (Cj, tm+d), d>0.
Below code is an implementation of the above two rules (simulation). Output is also shown for
clarity. Your task is to modify the below program such that value of ‘d’ becomes 3 for all the
processes, and the starting value of the clock at P1, P2, and P3 is 4. Submit the code with a
snapshot of the run.
Code:
#include<stdio.h>
int main()
{
int p1[10],p2[10];
int e,i,m1,m2;
printf("\n enter the no of events in p1 and p2\n");
scanf("%d",&e);
printf("\n enter the event of p1 which will send msg\n");
scanf("%d",&m1);
printf("\n enter the event of p2 which will receive the msg\n");
scanf("%d",&m2);
p2[0]=0;
for(i=1;i<=e;i++) Output:
{
if(i==m2)
{
if(m1>p2[i-1])
p2[i]=m1+1;
else
{
p2[i]=p2[i-1]+1;
}
}
else
{
p2[i]=p2[i-1]+1;
}
}
Submission instruction: Pl submit your all source files and snapshot of code run through the
submission portal.
--------------------------------