#include<bits/stdc++.h> using namespace std; double fact (int a)//计算n的阶乘 { double t=1.0; int i; for(i=1;i<=a;i++) t=t*i; return t; } double mi (int b, double angle)//计算x的n次方 { int j=1; double x=angle; for(j=1;j<b;j++) x=x*angle; return x; } int main() { int x,i=1,m=1,e=1; const double pi=3.141593; double p1,p2,sum=1.0,k=1,angle,shang=1; double fact (int); double mi (int b,double angle);// cout<<"请输入一个角度值 "; cin>>x; angle=pi*x/180; while(fabs(k)>=1e-7)//10的n次方的表达 { e=-e;//挺妙 m=2*i; p1=fact(m)*e; p2=mi(m,angle); k=p2/p1; shang=k; sum=sum+k; i++; } cout<<"cos("<<x<<")"<<'='<<sum<<endl; system("pause"); }
这道题明显用函数比较方便
标签:泰勒,p2,p1,angle,int,公式,sum,余弦,double From: https://www.cnblogs.com/zhengmou/p/17338617.html