Skip to content

Instantly share code, notes, and snippets.

/PI.c

Created February 2, 2012 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1723546 to your computer and use it in GitHub Desktop.
Save anonymous/1723546 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define R 1
#define INTERVAL 0.00001
int main()
{
long inCircleCount = 0;
double x, y;
for (y = 0; y < R; y += INTERVAL)
for (x = 0; x < R; x += INTERVAL)
if (x*x + y*y < R*R)
++inCircleCount;
printf("PI: %f\n", (double)inCircleCount * (INTERVAL * INTERVAL) * 4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment