用c语言写程序:求1000到2000之间所有能被67整除的数的和
时间: 2024-03-20 21:41:23 浏览: 65
下面是用 C 语言编写的程序,可以计算 1000 到 2000 之间所有能被 67 整除的数的和:
```c
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1000; i <= 2000; i++) {
if (i % 67 == 0) {
sum += i;
}
}
printf("1000到2000之间所有能被67整除的数的和为: %d\n", sum);
return 0;
}
```
程序的思路很简单,就是用一个循环遍历 1000 到 2000 之间的所有数,如果某个数能被 67 整除,就把它加到求和变量 `sum` 中。最后输出 `sum` 的值即可。
相关问题
用c语言写程序:1000到2000之间所有能被67整除的数的和
下面是用 C 语言编写的程序,可以计算 1000 到 2000 之间所有能被 67 整除的数的和:
```c
#include <stdio.h>
int main() {
int sum = 0;
for (int i = 1000; i <= 2000; i++) {
if (i % 67 == 0) {
sum += i;
}
}
printf("1000到2000之间所有能被67整除的数的和为: %d\n", sum);
return 0;
}
```
程序的思路很简单,就是用一个循环遍历 1000 到 2000 之间的所有数,如果某个数能被 67 整除,就把它加到求和变量 `sum` 中。最后输出 `sum` 的值即可。
使用c语言编写程序:打印1到100之间所有能被7整除的数每个数单独一行,计算并输出这些数的和
好的,我明白了。以下是使用C语言编写程序打印1到100之间所有能被7整除的数并计算这些数的和:
```c
#include <stdio.h>
int main() {
int sum = 0; // 用于存放能被7整除的数的和
for (int i = 1; i <= 100; i++) {
if (i % 7 == 0) { // 判断是否能被7整除
printf("%d\n", i); // 打印能被7整除的数
sum += i; // 累加能被7整除的数
}
}
printf("这些数的和是:%d", sum); // 输出能被7整除的数的和
return 0;
}
```
希望这个答案能够帮助到您!
阅读全文
相关推荐
















