Last active
February 15, 2017 05:53
-
-
Save mattearly/767a3a9bd589c89b0b2485f78928169e 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 <iostream> | |
static long num_steps = 100000; | |
double step; | |
void main() { | |
int i; | |
double x=0.0,pi=0.0,sum=0.0; | |
step = 1.0/(double)num_steps; | |
for (i=0;i<num_steps;i++) { | |
x = (i+0.5)*step; | |
sum += 4.0/(1.0+x*x); | |
} | |
pi = step * sum; | |
std::cout << pi << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment