當前位置:首頁 » 編程語言 » 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>。

熱點內容
c語言跳出死循環 發布:2025-05-15 20:06:04 瀏覽:823
a19處理器相當於安卓哪個水平 發布:2025-05-15 20:05:29 瀏覽:638
榮耀9i安卓強行關機按哪個鍵 發布:2025-05-15 20:00:32 瀏覽:750
密碼鎖寫什麼最好 發布:2025-05-15 19:05:31 瀏覽:782
5的源碼是 發布:2025-05-15 19:04:07 瀏覽:719
c語言創建的源文件 發布:2025-05-15 18:54:08 瀏覽:611
3個數字密碼鎖有多少種 發布:2025-05-15 18:49:48 瀏覽:684
壓縮包手機打開 發布:2025-05-15 18:37:34 瀏覽:217
安卓取消耳機模式怎麼取消 發布:2025-05-15 18:24:24 瀏覽:59
氣球怎麼解壓視頻 發布:2025-05-15 18:20:00 瀏覽:783