7-50 近似求PI (15 分)

思路:只要最后一项小于给定精度 就跳出循环 保留五位小数输出即可

#include <stdio.h>
int main(){
    double eps, sum=1, i, temp=1;
    scanf("%le", &eps);
    for(i=1; temp>eps; i++){
        temp = temp*i/(2*i+1);
        sum += temp;
    }
    printf("PI = %.5f\n", 2*sum);

    return 0;
}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2021-12-13
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2021-11-19
  • 2022-12-23
  • 2021-08-05
相关资源
相似解决方案