我们给出 x 和 n 的值,其中 x 是 cos 的角度,n 是 cos(x) 级数中的项数。
对于 Cos(x) h3>
Cos(x)是一个三角函数,用于计算x角度的值。

公式
$$cos (x) = displaystylesumlimits_{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 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程序的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444107.html
微信扫一扫
支付宝扫一扫