// // pi // #include #include const int n=1000000; inline double f(double x) { return 4/(x*x+1); } int main() { double a=0.0, b=1.0; double h=(b-a)/n; double mypi=0.0; int i; mypi = f(a) + f(b); for(i=1; i<=n; i++) { mypi = mypi + f(a+i*h); } mypi = h*mypi; printf("mypi=%.10f, err=%.2e\n", mypi, fabs(mypi-4*atan(1))); return 0; }