Last active
December 29, 2018 11:22
-
-
Save dipu-bd/908841c2ddcad993c9511632e0e71448 to your computer and use it in GitHub Desktop.
Calculates the value of PI
This file contains hidden or 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<bits/stdc++.h> | |
| using namespace std; | |
| int main() | |
| { | |
| double b, h, pi; | |
| pi = 2; // area of the rectangle | |
| b = 0.5 * sqrt(2.0); // initial base | |
| for(int i = 2; i <= 25; ++i) | |
| { | |
| h = 1 - sqrt(1 - x * x); // the height | |
| pi += pow(2, i) * b * h; // add the area | |
| b = 0.5 * sqrt(b * b + h * h); // the next base | |
| } | |
| printf("%.14f\n", pi); | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://medium.com/@dipu.sudipta/calculating-the-value-of-pi-%CF%80-from-basic-geometry-and-some-c-549e278afd03