Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2012 13:35
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/1723500 to your computer and use it in GitHub Desktop.
Save anonymous/1723500 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define R 10000
int main()
{
int inCircleCount = 0;
int x, y;
for (y = 0; y < R; ++y)
for (x = 0; x < R; ++x)
if (x*x + y*y < R*R)
++inCircleCount;
printf("PI: %f\n", (double)inCircleCount / (R * R) * 4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment