bilibiliC++36程序流程结构-循环结构案例-敲桌子
练习案例:敲桌子
案例描述:从1开始数到数字100, 如果数字个位含有7,或者数字十位含有7,或者该数字是7的倍数,我们打印敲桌子,其余数字直接打印输出。
#include<iostream>
#include<ctime>
using namespace std;
int main() {
for (int i = 1; i <= 100; i++)
{
if ((i % 7 == 0) || (i / 10 == 7) || (i % 10 == 7))
{
cout << "敲桌子" << endl;
}
else
{
cout << i << endl;
}
}
system("pause");
return 0;
}
/* 1 2 3 4 5 6 敲桌子 8 9 10 11 12 13 敲桌子 15 16 敲桌子 18 19 20 敲桌子 22 23 24 25 26 敲桌子 敲桌子 29 30 31 32 33 34 敲桌子 36 敲桌子 38 39 40 41 敲桌子 43 44 45 46 敲桌子 48 敲桌子 50 51 52 53 54 55 敲桌子 敲桌子 58 59 60 61 62 敲桌子 64 65 66 敲桌子 68 69 敲桌子 敲桌子 敲桌子 敲桌子 敲桌子 敲桌子 敲桌子 敲桌子 敲桌子 敲桌子 80 81 82 83 敲桌子 85 86 敲桌子 88 89 90 敲桌子 92 93 94 95 96 敲桌子 敲桌子 99 100 请按任意键继续. . . */
还没有评论,来说两句吧...