c語言近似值
發布時間: 2022-12-22 03:07:24
1. 用c語言計算sin(x)的近似值的代碼
根據台勞公式:
sin(x)=x-(x^3)/3!+(x^5)/5!+……(-1)^(n)x^(2n+1)/(2n+1)!
採用遞推法根據級數的前20項計算sin(x)的近似值:
(注: x為弧度值, x^(n+1)表示x的n+1次方)
我寫的代碼如下:
# include <stdio.h>
int main ()
{
double sx,x,a,b;
int n,f=1;
printf ("Please input x:");
scanf ("%lf",&x);
sx=a=x;
b=1;
for (n=1;n<=20;++n)
{
a*=x*x;
b*=4*n*n+2*n;
f=-f;
sx+=a/b*f;
}
printf ("sin(x)=%lf\n",sx);
return 0;
}
希望對你有所幫助。
2. 如何用C語言設計計算cosx的近似值
1、首先在電腦中打開Dev-C++,接著在打開的操作主頁面中,寫好頭函數#include <stdio.h>#include <math.h>。
熱點內容