Advertisement
Guest User

pi

a guest
May 29th, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. const int c = 10000000;
  6.  
  7. int main() {
  8.     srand ( time(NULL) );
  9.  
  10.     float x,y,i=0.0;
  11.     int s;
  12.     for(s=0; s<c; s++) {
  13.         x=1.*rand()/RAND_MAX;
  14.         y=1.*rand()/RAND_MAX;
  15.         i+=x*x+y*y<=1;
  16.     }
  17.     printf("%lf\n",4*i/c);
  18.  
  19.     return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement