热门

最新

红包

立Flag

投票

同城

我的

发布
m0_74406976
yumekii-
4 年前
truem0_74406976

已知cosx的幂级数为:
cos(x)=1−x22!+x44!−x66!+...+(−1)nx2n(2n)!+...cos(x)=1−x22!+x44!−x66!+...+(−1)nx2n(2n)!+…设计程序用于计算幂级数中的通项(−1)nx2n(2n)!(−1)nx2n(2n)!的值,并计算cosx的值(结果保留4位有效数字),通项精度不小于0.00001。
#include<iostream>
#include<math.h>
#include<iomanip>
int main() {
using namespace std;
double x,sum=1;
static double t=1;
cin>>x;
for (int i=1;fabs(t)>0.00001;i++) {
t*=x*x;
t/=2*i*(2*i-1);
t*=-1;
sum+=t;
}
cout<<"cos("<<x<<") = "<<fixed<<setprecision(4)<<sum;
return 0;
}

CSDN App 扫码分享
分享
1
点赞
打赏
  • 复制链接
  • 举报
下一条动态
立即登录