Saturday, 26 January 2013


Aim: Finding the Maximum and Minimum of Numbers.
MSc IT Parallel Processing Practical No. 8
Index of all Practicals ~ Click Here


Code:
#include<stdio.h>
#include"shmlib.h"
int main()
{
int *result,*result1,num[6],x,id1,id2,id,val,i,final;
                  
result=(int *) shared(sizeof(int),&id1);
result1=(int *) shared(sizeof(int),&id2);
printf("Enter values");                                     

for(x=0;x<6;x++)
{
scanf("%d",&num[x]);
}

id=create_process(2);

if(id==0)
{
if(num[0]>=num[1])
{
result[0]=num[0];
result1[0]=num[1];
}
else
{
result[0]=num[1];
result1[0]=num[0];
}
}
if(id==1)
{
if(num[2]>=num[3])
{
result[1]=num[2];
result1[1]=num[3];
}
else
{
result[1]=num[3];
result1[1]=num[2];}}
if(id==2)
{
if(num[4]>=num[5])
{
result[2]=num[4];
result1[2]=num[5];
}
else
{
result[2]=num[5];
result1[2]=num[4];
}
}

join_process(3,id);

id=create_process(0);

if(id==0)
{
if(result[0]>=result[1])
{
result[3]=result[0];
}
else
{
result[3]=result[1];
}
}

if(result[3]>result[2])
{
    printf("Maximum no is %d",result[3]);
}
else
{
    printf("Maximum no is %d",result[2]);
}

join_process(1,id);

id=create_process(0);

if(id==0)
{
if(result1[0]<=result1[1])
{
result1[3]=result1[0];
}
else
{
result1[3]=result1[1];
}
}

if(result1[3]<result1[2])
{
    printf("\n Minimum no is %d",result1[3]);
}
else
{
    printf("\n Minimum no is %d",result1[2]);
}

join_process(1,id);
return 0;
}

Output:

Related Posts :



0 comments:

Confused? Feel free to ask

Post a Comment