c语言 将100-500之间既能被3整除又能被7整除的数输出,每行输出5个。 请分别用三种循环实现
时间: 2023-11-14 13:04:37 浏览: 100
可以用以下三种循环实现:
方法一:for循环
```c
#include <stdio.h>
int main()
{
int count = 0;
for (int i = 100; i <= 500; i++)
{
if (i % 3 == 0 && i % 7 == 0)
{
printf("%d ", i);
count++;
}
if (count == 5)
{
printf("\n");
count = 0;
}
}
return 0;
}
```
方法二:while循环
```c
#include <stdio.h>
int main()
{
int i = 100;
int count = 0;
while (i <= 500)
{
if (i % 3 == 0 && i % 7 == 0)
{
printf("%d ", i);
count++;
}
if (count == 5)
{
printf("\n");
count = 0;
}
i++;
}
return 0;
}
```
方法三:do-while循环
```c
#include <stdio.h>
int main()
{
int i = 100;
int count = 0;
do
{
if (i % 3 == 0 && i % 7 == 0)
{
printf("%d ", i);
count++;
}
if (count == 5)
{
printf("\n");
count = 0;
}
i++;
} while (i <= 500);
return 0;
}
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.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)
![](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)