Last active
April 20, 2021 08:46
-
-
Save lefuturiste/7ae137ec8591ffc200e3e13becaa1dec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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