Guest User

Untitled

a guest
Mar 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4.  
  5. #define INT_MAX 16
  6. int main(int argc, char** argv)
  7. {
  8. srand(time(NULL));
  9. int i;
  10. if(argv[1]!=NULL)
  11. {
  12. int vrednost=atoi(argv[1]);
  13. for(i=1; i<=vrednost; i++)
  14. {
  15. int p[2];
  16. int fo=fork();
  17. if(fo==0)
  18. {
  19. double x = (double)rand()/(double)INT_MAX;
  20. double y = (double)rand()/(double)INT_MAX;
  21.  
  22. write(p[1], &x, sizeof(x));
  23. write(p[1], &y, sizeof(y));
  24.  
  25. _exit(0);
  26. }
  27. else
  28. {
  29. int n=0;
  30. int N=0;
  31. double x = 0.0;
  32. double y = 0.0;
  33. read(p[0], &x, sizeof(x));
  34. read(p[0], &y, sizeof(y));
  35. double z;
  36. z=x*x+y*y;
  37. if(z<1.0)
  38. {
  39. n=n+1;
  40. }
  41. N=N+1;
  42. double izraz=n/n*4.0;
  43. printf("Vrednost izraza %f", izraz);
  44.  
  45. }
  46. int e;
  47. for(e=1; e<=vrednost; e++)
  48. {
  49. wait(NULL);
  50. }
  51. }
  52. }
  53. else
  54. {
  55. printf("Za imenom programa prosim vpisi zeljeno celo stevilo. Hvala in lep pozdrav!\n");
  56. }
  57.  
  58. return 0;
  59. }
Add Comment
Please, Sign In to add comment