c語言編程 cos(x)=1-x^2/2!+x^3/3!-x^4/4!+.-x^10/10!
題目:
c語言編程 cos(x)=1-x^2/2!+x^3/3!-x^4/4!+.-x^10/10!
具體題目如下:輸入x,按下列公式計算cos(x)的近似值.
cos(x)=1-x^2/2!+x^3/3!-x^4/4!+.-x^10/10!
解答:
下面是代碼 ,我測試過是對的,
#include
#include
/*求階乘函數*/
int jiecheng(int n)
{
if(n < 0){
printf("錯誤的數字\n");
return -1;
}
else if( n == 0 || n== 1){
return 1;
}
else{
return jiecheng(n-1)*n;
}
}
/*自己寫的cos 函數*/
double mycos(double x)
{
int i = 2;
double sum = 1.0f;
int k = -1;
while(i
添加新評論