2025-03-06 22:45:14 +08:00

29 lines
485 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
编程计算π的近似值直到最后一项的绝对值小于10-5为止使用while:
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
#define N 1e-5
main()
{
int i,f;
double t,s;
f=1;
s=0;
i=1;
t=1.0;
/**********Program**********/
while(fabs(t/i)>N){
s+=t/i*f;//计算该项的值
f*=-1;//翻转符号
i+=2;
}
/********** End **********/
s=s*4 ;
printf("圆周率的近似值为:%f\n",s);
}