练习案例:敲桌子
案例描述:从1开始数到数字100, 如果数字个位含有7,或者数字十位含有7,或者该数字是7的倍数,我们打印敲桌子,其余数字直接打印输出。
例程如下:
#include <iostream>
using namespace std;
int main() {
int num;
for (num = 1; num<= 100; num++) {
if (num < 10)
if (num == 7 || num % 7 == 0)
cout << "敲桌子" << endl;
else
cout << num << endl;
else if (num < 100)
if (num % 10 == 7 || num / 10 == 7 || num % 7 == 0)
cout << "敲桌子" << endl;
else
cout << num << endl;
else
if (num % 10 == 7 || (num / 10) % 10 == 7 || num % 7 == 0)
cout << "敲桌子" << endl;
else
cout << num << endl;
}
system("pause");
return 0;
}