用do-while语句求1至1000之间满足 "用3除余2;且用5除余3"的数,且一行只打印五个数
时间: 2023-05-28 07:05:08 浏览: 61
int i = 1;
int count = 0;
do {
if(i % 3 == 2 && i % 5 == 3) {
cout << i << " ";
count++;
if(count % 5 == 0) {
cout << endl;
}
}
i++;
} while(i <= 1000);
相关问题
用 do - while 语句求1至1000之间满足"用3除余2;且用5除余3"的数,且一行只打印五个数。
以下是代码实现:
int i = 1;
int count = 0;
do {
if (i % 3 == 2 && i % 5 == 3) {
printf("%d ", i);
count++;
if (count % 5 == 0) {
printf("\n");
}
}
i++;
} while (i <= 1000);
注意:以上代码是用 C 语言实现的,可以在编译器中运行。
c语言用do-while语句求1至1000之间满足 "用3除余2;且用5除余3"的数,且一行只打印五个数
```c
#include<stdio.h>
int main(){
int i = 1;
int count = 0;
do{
if(i%3 == 2 && i%5 == 3){
printf("%d ", i);
count++;
if(count == 5){
printf("\n");
count = 0;
}
}
i++;
}while(i <= 1000);
return 0;
}
```