用C语言编写代码输出1到100的和
时间: 2024-02-06 09:09:04 浏览: 118
c语言1到100求和
下面是一个用C语言编写的输出1到100的和的代码:
```c
#include <stdio.h>
int main() {
int i, sum = 0;
for (i = 1; i <= 100; i++) {
sum += i;
}
printf("The sum of 1 to 100 is %d\n", sum);
return 0;
}
```
运行结果:
```
The sum of 1 to 100 is 5050
```
阅读全文