Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #define INT_MAX 16
- int main(int argc, char** argv)
- {
- srand(time(NULL));
- int i;
- if(argv[1]!=NULL)
- {
- int vrednost=atoi(argv[1]);
- for(i=1; i<=vrednost; i++)
- {
- int p[2];
- int fo=fork();
- if(fo==0)
- {
- double x = (double)rand()/(double)INT_MAX;
- double y = (double)rand()/(double)INT_MAX;
- write(p[1], &x, sizeof(x));
- write(p[1], &y, sizeof(y));
- _exit(0);
- }
- else
- {
- int n=0;
- int N=0;
- double x = 0.0;
- double y = 0.0;
- read(p[0], &x, sizeof(x));
- read(p[0], &y, sizeof(y));
- double z;
- z=x*x+y*y;
- if(z<1.0)
- {
- n=n+1;
- }
- N=N+1;
- double izraz=n/n*4.0;
- printf("Vrednost izraza %f", izraz);
- }
- int e;
- for(e=1; e<=vrednost; e++)
- {
- wait(NULL);
- }
- }
- }
- else
- {
- printf("Za imenom programa prosim vpisi zeljeno celo stevilo. Hvala in lep pozdrav!\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment