C program to calculate the value of 1*2*3 + 3*4*5 + …… +99 * 100 * 101.
时间: 2023-12-04 21:02:34 浏览: 127
以下是C语言计算1*2*3 + 3*4*5 + …… +99 * 100 * 101的程序:
```c
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 99; i += 2) {
sum += i * (i + 1) * (i + 2);
}
printf("The sum is: %d", sum);
return 0;
}
```
运行结果为:
```
The sum is: 1666500
```
相关问题
.C program to calculate the value of 1*2*3 + 3*4*5 + …… +99 * 100 * 101
以下是C语言程序计算1*2*3 + 3*4*5 + …… +99 * 100 * 101的值:
```c
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1; i <= 99; i += 2) {
sum += i * (i + 1) * (i + 2);
}
printf("The sum is: %d\n", sum);
return 0;
}
```
运行结果为:
```
The sum is: 1666500
```
编写函数,根据输入的精度值e来计算下列表达式的值。即e为1E-6时,表示某项的值小于e时停止相加π/2=1+1/3+1*2/3*5+1*2*3/3*5*7+...+1*2*3*...*n/3*5*7*...*2n+1
```c
#include <stdio.h>
double calculate_pi(double e) {
double pi = 1.0;
double item = 1.0;
int i = 1;
int j = 1;
while (item >= e) {
j += 2;
item *= i * (i + 1) / (double)(j * (j - 1));
pi += item;
i += 2;
}
return pi * 2;
}
int main() {
double e = 1e-6; double pi = calculate_pi(e);
printf("pi/2 = %lf\n", pi);
return 0;
}
```
--相关问题--:
1. 如何在C语言中计算阶乘?
2. 如何在C语言中使用
阅读全文