[ create a new paste ] login | about

Link: http://codepad.org/xtKNLR4P    [ raw code | output | fork ]

mohit_at_codepad - C, pasted on Apr 26:
/* Print the value of pi */
#include <stdio.h>
#include <stdlib.h>
#if 0
#define const
typedef int my_int;
#endif

typedef long long int my_int;
const my_int RADIUS  = 2 * 1000 * 1000;

int main() {
  const my_int SQRADIUS= RADIUS * RADIUS;
  my_int numHits = 0;
  my_int x = 0;
  my_int y = RADIUS;
  for(x = 1; x <= RADIUS; ++x) {
    my_int ySq = SQRADIUS - x*x;
    while(y*y > ySq) --y;
    numHits += 2 * y;
  }
  printf("Value of pi is: %g\n", 2.0 * numHits / SQRADIUS);
  return 0;
}


Output:
1
Value of pi is: 3.14159


Create a new paste based on this one


Comments: