您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

求cos(x)级数的C程序

2025/4/19 20:32:08发布24次查看
我们给出 x 和 n 的值,其中 x 是 cos 的角度,n 是 cos(x) 级数中的项数。
对于 cos(x) h3>cos(x)是一个三角函数,用于计算x角度的值。
公式$$\cos (x) = \displaystyle\sum\limits_{k=0} ^\infty \frac{(-1)^{k}}{(2k!)}x^{2k}$$
对于 cos(x) 级数cos( x) = 1 – (x*2 / 2!) + (x*4 / 4!) – (x*6 / 6!) + (x*8 / 8!)……
示例input-: x = 10, n = 3output-: 0.984804input-: x = 8, n = 2output-: 0.990266
下面程序中使用的方法如下 -
输入x和n的值应用cos(x)级数的计算公式打印结果作为所有级数的总和算法startstep 1 declare and initialize const double pi = 3.142step 2 in function double series_sum(double x, int n) set x = x * (pi / 180.0)set result = 1set s = 1, fact = 1, pow = 1 loop for i = 1 and i < 5 and i++ set s = s * -1 set fact = fact * (2 * i - 1) * (2 * i) set pow = pow * x * x set result = result + s * pow / fact end loop return resultstep 3 in function int main() s declare and set x = 10declare and set n = 3 print series_sum(x, n) stop
示例#include <stdio.h>const double pi = 3.142;//will return the sum of cos(x)double series_sum(double x, int n) { x = x * (pi / 180.0); double result = 1; double s = 1, fact = 1, pow = 1; for (int i = 1; i < 5; i++) { s = s * -1; fact = fact * (2 * i - 1) * (2 * i); pow = pow * x * x; result = result + s * pow / fact; } return result;}//main functionint main() { float x = 10; int n = 3; printf("%lf
", series_sum(x, n)); return 0;}
输出x=10; n=30.984804x=13; n=80.974363x=8; n=2 0.990266
以上就是求cos(x)级数的c程序的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product