Skip to content

Instantly share code, notes, and snippets.

@dipu-bd
Last active December 29, 2018 11:22
Show Gist options
  • Select an option

  • Save dipu-bd/908841c2ddcad993c9511632e0e71448 to your computer and use it in GitHub Desktop.

Select an option

Save dipu-bd/908841c2ddcad993c9511632e0e71448 to your computer and use it in GitHub Desktop.
Calculates the value of PI
#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;
}
@dipu-bd
Copy link
Author

dipu-bd commented Dec 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment