如何用c语言表达(1)循环数字1到200,并打印出该数字; (2)但不打印5的倍数(学习使用continue) (3)当碰到9的倍数时,除了打印该数字,还要打印一句话“This is multiple of 9” (4)当循环到190时,不再打印任何数字(学习使用break)
时间: 2023-04-09 11:04:20 浏览: 82
以下是用 C 语言表达循环数字 1 到 200 并满足上述要求的代码:
```c
#include <stdio.h>
int main() {
for (int i = 1; i <= 200; i++) {
if (i % 5 == 0) {
continue;
}
if (i % 9 == 0) {
printf("%d This is multiple of 9\n", i);
} else {
printf("%d\n", i);
}
if (i == 190) {
break;
}
}
return 0;
}
```
注意,这里使用了 `continue` 和 `break` 语句来实现题目要求。`continue` 语句可以跳过当前循环中的剩余语句,直接进入下一次循环;而 `break` 语句可以跳出当前循环,直接执行循环后的语句。
相关问题
用c语言(1)循环数字1到200,并打印出该数字; (2)但不打印5的倍数(学习使用continue) (3)当碰到9的倍数时,除了打印该数字,还要打印一句话“This is multiple of 9” (4)当循环到190时,不再打印任何数字(学习使用break)
以下是代码:
```c
#include <stdio.h>
int main() {
for (int i = 1; i <= 200; i++) {
if (i % 5 == 0) {
continue;
}
if (i % 9 == 0) {
printf("%d This is multiple of 9\n", i
用c语言随机生成5个数字并打印
好的,请稍等,让我来为您提供代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i, num;
srand((unsigned)time(NULL));
for(i = 0; i < 5; i++) {
num = rand() % 100;
printf("%d ", num);
}
return 0;
}
```
这段代码中,我们使用了 `srand()` 函数来初始化随机数生成器,`rand()` 函数来生成随机数。在本例中,我们生成了 5 个在 0 到 99 之间的随机数,并打印输出。希望这能帮到您,有其他问题可以随时向我提问。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)