SHARE
TWEET

pi

a guest May 29th, 2012 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top