Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- const int c = 10000000;
- int main() {
- srand ( time(NULL) );
- float x,y,i=0.0;
- int s;
- for(s=0; s<c; s++) {
- x=1.*rand()/RAND_MAX;
- y=1.*rand()/RAND_MAX;
- i+=x*x+y*y<=1;
- }
- printf("%lf\n",4*i/c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement