Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <sys/wait.h>
- #define RADIUS 0.5
- int main(int argc, char *argv[])
- {
- if (argc < 2) {
- printf("Not enough args\n");
- return 0;
- }
- int iters = atoi(argv[1]);
- int i, count = 0;
- double x, y;
- for (i = 0; i < iters; i++)
- {
- x = RADIUS - drand48();
- y = RADIUS - drand48();
- if (x * x + y * y < RADIUS * RADIUS) count++;
- }
- printf("%f\n", 4.0 * (double)count / (double)iters);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement