#include "headfork.h"// included in attachment
#include "headsem.h"//#include "headbar.h"
#include "headshr.h"
#include<stdio.h>
#include<math.h>
main()
{
float a[10];
int *lock,*bar,shmid1,shmid2,shmid3;
float *avg,*dev,sum;
int id,n,np,i;
avg=(float *)shared(sizeof(float)*2,&shmid1);
dev=(float *)shared(sizeof(float)*2,&shmid2);
lock=shared(sizeof(int)*2,&shmid3);
printf("Enter the limit of array :" );
scanf("%d",&n);
printf("Enter the elemts of array:\n");
for(i=0;i<n;i++)
scanf("%f",&a[i]);
printf("Enter the no.of proc: ");
scanf("%d",&np);
*avg=0.0;
*dev=0.0;
// bar=bar_init(np);
id=p_fork(np);
sum=0.0;
for(i=id;i<n;i+=np)
sum+=a[i];
locksem(lock);
*avg=*avg + sum/(float)n;
unlock(lock);
// barrier(bar);
sum=0.0;
for(i=id;i<n;i+=np)
sum=sum + abs(a[i] - *avg);
locksem(lock);
*dev=*dev + sum/(float)n;
unlock(lock);
p_join(np,id);
printf("Deviation : %f",*dev);
}