60.根据公式计算值

论坛 期权论坛 脚本     
匿名技术用户   2021-1-14 14:39   23   0

给定程序中函数fun的功能是: 根据以下公式求P值,并作为函数的返回值。


#define _CRT_SECURE_NO_WARNINGS
#include<math.h>
#include<stdio.h>
double fun(double eps)
{
 double s, t;
 int n = 1;
 s = 0.0;
 t = 1.0;
 while (t >eps)
 {
  s += t;
  t = t*n / (2*n + 1);
  n++;
 }
 return(2*s);
}
int main()
{
 double x;
 printf("\nPlease enter a precision :");
 scanf("%lf", &x);
 printf("\neps=%lf ,Pi=%lf\n\n", x, fun(x));
 getchar();
 getchar();
 return 0;
}


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP