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

$$\cos (x) = \displaystyle\sum\limits_{k=0} ^\infty \frac{(-1)^{k}}{(2k!)}x^{2k}$$
本书以培养高级网站建设与管理人才为目标,内容循序渐进,由浅入深,通过大量的实例系统全面地介绍了Linux+PHP+MySQL环境下的网络后台开发技术。本书详尽分析了近30个典型案例。包括计数器、网站流量统计、留言板、论坛系统、聊天室、投票与调查、用户管理、新闻发布系统、广告轮播、购物系统等等,力求让读者通过对案例的学习,轻松掌握PHP和MySQL的编程精要,迅速掌握网络后台开发技巧。 本书适
466
Cos( x) = 1 – (x*2 / 2!) + (x*4 / 4!) – (x*6 / 6!) + (x*8 / 8!)……
Input-: x = 10, n = 3 Output-: 0.984804 Input-: x = 8, n = 2 Output-: 0.990266
下面程序中使用的方法如下 -
Start
Step 1 Declare and initialize const double PI = 3.142
Step 2 In function double series_sum(double x, int n)
Set x = x * (PI / 180.0)
Set result = 1
Set 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 result
Step 3 In function int main() s
Declare and set x = 10
Declare 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 function
int main() {
float x = 10;
int n = 3;
printf("%lf</p><p>", series_sum(x, n));
return 0;
}X=10; n=30.984804 X=13; n=80.974363 X=8; n=2 0.990266
以上就是求cos(x)级数的C程序的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号