# include # include # include using namespace std; int fac(int x) { register int i,f=1; for(i=1;i<=x;i++) f*=i; return f; } int main() { double x,sum=0,c; double i=0; cin>>x; c=x; for(i=0;;i++) { x=(pow(c,2*i+1)*pow(-1,i))/fac(2*i+1); sum=sum+x; if(abs((pow(c,2*i+1)*pow(-1,i))/fac(2*i+1))<1e-6) break; } cout << fixed << setprecision(5) << sum; return 0; }
4条回答 默认 最新
- technologist_30 2021-05-25 23:19关注
#include <stdio.h> #include <math.h> double fact(int n) { if (n == 0) return 1; return fact(n - 1)*n; } int main() { double x, sum = 0, term = 1; int n = 1, t = 1; scanf("%lf", &x); while (term >= 1e-5) { term = pow(x, 2 * n - 1) / fact(2 * n - 1); sum += t * term; t = -t; n++; } printf("%.3lf\n%d", sum, n - 1); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题
- ¥15 phython路径名过长报错 不知道什么问题
- ¥15 深度学习中模型转换该怎么实现
- ¥15 HLs设计手写数字识别程序编译通不过
- ¥15 Stata外部命令安装问题求帮助!
- ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
- ¥15 TYPCE母转母,插入认方向
- ¥15 如何用python向钉钉机器人发送可以放大的图片?