Skip to content

Instantly share code, notes, and snippets.

@lefuturiste
Last active April 20, 2021 08:46
Show Gist options
  • Save lefuturiste/7ae137ec8591ffc200e3e13becaa1dec to your computer and use it in GitHub Desktop.
Save lefuturiste/7ae137ec8591ffc200e3e13becaa1dec to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
int main()
{
int n = 100000;
double size = 1.0 / n;
double area = 0.0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
double x = i * size + size / 2;
double y = j * size + size / 2;
double r = pow(x, 2.0) + pow(y, 2.0);
if (r <= 1)
{
area = area + (size * size);
}
}
}
printf("%.15f", area*4);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment