Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <sys/wait.h>
  5.  
  6. #define RADIUS 0.5
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.     if (argc < 2) {
  11.         printf("Not enough args\n");
  12.         return 0;
  13.     }
  14.     int iters = atoi(argv[1]);
  15.     int i, count = 0;
  16.     double x, y;
  17.     for (i = 0; i < iters; i++)
  18.     {
  19.         x = RADIUS - drand48();
  20.         y = RADIUS - drand48();
  21.         if (x * x + y * y < RADIUS * RADIUS) count++;
  22.     }
  23.     printf("%f\n", 4.0 * (double)count / (double)iters);
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement