Skip to content

Instantly share code, notes, and snippets.

@sidward35
Last active July 13, 2017 02:42
Show Gist options
  • Save sidward35/f6e85980e98aaf2e709e4dd99446bdcb to your computer and use it in GitHub Desktop.
Save sidward35/f6e85980e98aaf2e709e4dd99446bdcb to your computer and use it in GitHub Desktop.
C++ Print Pi
#include <iostream>
#include <math.h>
int main(){
double x=sqrt(12)*(1-(1/(3*pow(3,1)))+(1/(5*pow(3,2)))-(1/(7*pow(3,3)))+(1/(9*pow(3,4)))-(1/(11*pow(3,5)))+(1/(13*pow(3,6)))-(1/(15*pow(3,7)))+(1/(17*pow(3,8))));
std::cout<<"PI estimation\n";
std::cout<<"Estimation of PI without precision setting is "<<x<<"\n";
printf("Estimation PI shown with 12 decimal fraction digit is %.12f\n", x);
std::cout<<"PI value in cmath library is "<<M_PI<<"\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment