// pi.c
// Experiment for PI calculation via Riemann Integral
// By Tangent, [email protected]
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv)
{
// Our formula: PI=4* S(a,b, sqrt(1-x^2), dx
register double dx = pow(10,-7);
printf("Experimental dx value is %.7f\n",dx);
register double S=0.0;
for(register double x=0.0; x<=1; x+=dx)
{
printf("[LAP]\tx=%.7f\t",x);
register double x_pow = pow(x,2);
printf("x_pow=%.16f\t",x_pow);
register double xp_1 = 1-x_pow;
printf("xp_1=%.20f\t",xp_1);
register double x_sqrt = sqrt(xp_1);
printf("x_sqrt=%.40f\t",x_sqrt);
register double _S = x_sqrt*dx;
printf("PIECE=%.40f\t",_S);
S = S+_S;
printf("S=%.45f\n",S);
}
register double pi_res=0.0;
pi_res = S*4;
printf("===Results got===\nPI=%.128f\n",pi_res);
return 0;
}
C 计算 圆周率(定积分)
猜你喜欢
转载自blog.csdn.net/weixin_40732417/article/details/104383167
今日推荐
周排行