自学内容网 自学内容网

C++敲桌子游戏

题目:敲桌子:从1开始数到100,如果数字的个位或者十位为7,或者数字是7的倍数,则显示"敲桌子",否则显示数字本身

#include <iostream>
/*
敲桌子:从1开始数到100,如果数字的个位或者十位为7,或者数字是7的倍数,则显示"敲桌子",否则显示数字本身 
*/
using namespace std;

int main() {
for(int num  = 1; num <= 100; num++) {
if( !(num%7) || (num%10 == 7) || ( (num - num%10)/10 == 7)) {
// 是7的倍数 或  个位数字为7  或  十位数字为7 
cout << "敲桌子 ";
} else {
cout << num << ' '; 
} 
} cout << endl;//最后换行 

return 0;
} 


原文地址:https://blog.csdn.net/JackerCSDN/article/details/136357010

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!