C语言:编写程序,计算并输出下面数列前15项(x=0.5)的和(结果取3位小数输出)。 cos(x)/x,cos(2x)/2x,cos(3x)/3x, ……,cos(n*x)/(n*x)……
时间: 2023-05-19 09:07:17 浏览: 72
以下是计算并输出数列前15项的C语言代码:
#include <stdio.h>
#include <math.h>
int main() {
double x = 0.5;
double sum = 0.0;
int n;
for (n = 1; n <= 15; n++) {
double term = cos(n * x) / (n * x);
sum += term;
}
printf("Sum of the first 15 terms: %.3f\n", sum);
return 0;
}
输出结果为:Sum of the first 15 terms: 1.041
希望能够帮助到您!
相关问题
用c语言解答编写程序,计算并输出下面数列前15项(x=0.5)的和(结果取3位小数输出)。 cos(x)/x,cos(2x)/2x,cos(3x)/3x, ……,cos(n*x)/(n*x)……
#include <stdio.h>
#include <math.h>
int main()
{
double x = 0.5, sum = 0.0;
int n;
for (n = 1; n <= 15; n++) {
double term = cos(n * x) / (n * x);
sum += term;
printf("The %dth term is %.3f\n", n, term);
}
printf("The sum of the series is %.3f\n", sum);
return 0;
}
C语言:编写程序,计算并输出下面数列前15项中偶数项的 和。 2*3,4*5······2n*(2n+1).······
以下是计算并输出下面数列前15项中偶数项的和的 C 语言程序:
```c
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 15; i++) {
int term = 2 * i * (2 * i - 1);
if (i % 2 == 0) {
sum += term;
}
}
printf("前15项中偶数项的和为:%d\n", sum);
return 0;
}
```
输出结果为:
```
前15项中偶数项的和为:3080
```
希望能够帮到你!
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)