#include <iostream>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//pai的近似值=1-1/3+1/5-1/7+……;
int main(int argc, char** argv) {
double n,fenzi=1,fenmu=1,dangqianshu=1;
double fenshu=1,sum=0;
while(fabs(fenshu)>1e-6)
{
sum+=fenshu;
fenzi=-fenzi;
fenmu=fenmu+2;
fenshu=fenzi/fenmu;
}
printf("sum is %f",sum*4);
return 0;
}
c语言输出pai的近似值
最新推荐文章于 2021-05-25 17:54:41 发布