7-50 近似求PI (15分)

7-50 近似求PI (15分)

#include <cstdio>

int main(){
    double eps,sum=2,i,temp=1;
    scanf("%lf",&eps);
    for ( i=1; temp>eps; i++)
	{
      temp *=  i /(2*i+1);
      sum += temp*2 ;
    }
    printf("PI = %.5f",sum);
    return 0;
}

看别人写的,唉。

发布了64 篇原创文章 · 获赞 0 · 访问量 793

猜你喜欢

转载自blog.csdn.net/qq_38054511/article/details/104082896
今日推荐