Skip to content

Instantly share code, notes, and snippets.

@mattearly
Last active February 15, 2017 05:53
Show Gist options
  • Save mattearly/767a3a9bd589c89b0b2485f78928169e to your computer and use it in GitHub Desktop.
Save mattearly/767a3a9bd589c89b0b2485f78928169e to your computer and use it in GitHub Desktop.
#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