c语言把1~100之间能被7整除的数,以每行5个的形式在屏幕上输出
时间: 2024-05-03 14:20:52 浏览: 8
Sure, here's the C code to output all numbers between 1 and 100 that are divisible by 7, in rows of 5:
```c
#include <stdio.h>
int main()
{
int i;
for (i = 1; i <= 100; i++)
{
if (i % 7 == 0)
{
printf("%d ", i);
if (i % 35 == 0)
printf("\n");
}
}
return 0;
}
```
I hope that helps!
相关问题
C语言while编写程序在屏幕上输出1~100之间能被7整除的数,以每行输出10个的格式。
好的,这是一个比较简单的程序,可以使用while循环和if语句来实现,在这里给您写出代码,供参考:
```c
#include <stdio.h>
int main() {
int count = 0; // 计数器,用于控制每输出10个数再换行
int i = 1;
while (i <= 100) {
if (i % 7 == 0) {
printf("%d ", i);
count++;
if (count == 10) {
printf("\n");
count = 0;
}
}
i++;
}
return 0;
}
```
这个程序运行起来,会在屏幕上输出1~100之间能被7整除的数,每行输出10个,如下所示:
```
7 14 21 28 35 42 49 56 63 70
77 84 91 98
```
希望对您有帮助!还有什么问题可以继续问我哦~
c语言将1到100之间能被7整除不能被3整除的数每行五个输出
好的,以下是符合要求的C语言代码:
```c
#include <stdio.h>
int main() {
int count = 0;
for (int i = 1; i <= 100; i++) {
if (i % 7 == 0 && i % 3 != 0) {
printf("%d ", i);
count++;
if (count % 5 == 0) {
printf("\n");
}
}
}
return 0;
}
```
代码解释:
1. 首先定义一个计数器`count`,用于记录当前已输出的数的个数;
2. 然后使用`for`循环遍历1到100之间的所有数;
3. 对于每个数,判断它是否能够被7整除且不能被3整除;
4. 如果符合条件,则输出该数,并将计数器加1;
5. 如果当前已输出的数的个数是5的倍数,则在该数后输出一个换行符,以实现每行输出五个数的效果。
希望能够帮到你!