Pi calculation

One can calculate the value of Pi in the following way

#include <iostream>
#include<cmath>
using namespace std;

int main() {
int k ;
double val=0.0 , nval;

for(k=1;k<=1000000;k++)
{
val=val+ ( powf(-1,k+1)/(2*k-1) );
}
nval=4*val;

printf( "Approximate PI=%14.12lf\n ", nval );
printf( "Built in PI=%14.12lf\n ", M_PI );
return 0;
}


For more info www.cpluscode.blogspot.com
Last edited on
What's the question?
Topic archived. No new replies allowed.