求水仙花数和敲桌子小游戏(C++版)

求水仙花数

for循环书写水仙花数

#include<iostream>
using namespace std;
int main()
{
	int num = 0;
	int a=0, b=0, c=0;
	for (num=0;num<1000;num++)
	{
		a = num / 100;
		b = (num % 100) / 10;
		c = num % 10;
		
		if (num == a * a * a + b * b * b + c * c * c)
		{
			cout << "该数为水仙花数:" << num << endl;
		}
		
	}
	system("pause");
	return 0;
}

do while循环书写水仙花数

int main()
{
	int num =100;
	int a = 0, b = 0, c = 0;
	do
	{
		a = num / 100;
		b = (num % 100) / 10;
		c = num % 10;
		if (num == a * a * a + b * b * b + c * c * c)
		{
			cout << "该数为水仙花数:" << num << endl;
		}
		num++;
	} while (num < 1000);
	system("pause");
	return 0;
}

敲桌子小游戏

for循环书写

#include<iostream>
using namespace std;
int main()
{
	int num = 0;
	for (num = 0; num < 100; num++)
	{
		if (num % 10 == 7 || num / 10 == 7 || num % 7 == 0)
		{
			cout << "桌子" << endl;
		}
		else
		{
			cout << num << endl;
		}
	}
	system("pause");
	return 0;
}

原文链接: https://www.cnblogs.com/kk-sy/p/17094362.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    求水仙花数和敲桌子小游戏(C++版)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/316290

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月16日 下午2:10
下一篇 2023年2月16日 下午2:11

相关推荐