當前位置:首頁 » 編程語言 » c語言近似值

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>。

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:590
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:885
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:577
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:763
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:680
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1010
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:253
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:111
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:802
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:709