#include<stdio.h>
#include "headfork.h"// included in attachment
#include "headshr.h"
#include "headsem.h"
main()
{
int shmid,shmid1,shmid2;
int *ans,*lock1,mul;
int id,n,npc,j,i;
ans=shared(sizeof(int)*2,&shmid);
lock1=shared(sizeof(int)*2,&shmid1);
// ans=shared(sizeof(int)*2,&shmid2);
lock_init(lock1);
printf("Enter ant No: ");
scanf("%d",&n);
printf("Enter the no.of proc: ");
scanf("%d",&npc);
*ans=1;
id=p_fork(npc);
mul=1;
for(i=id+1;i<=n;i+=npc)
{
mul=mul*i;
}
locksem(lock1);
* ans = *ans * mul;
unlock(lock1);
p_join(npc,id);
printf("The Factorial of %d is: %d",n,*ans);
}