Problem E. S06-10水仙花数

水仙花数是指各位数字的立方和等于该数本身的三位数。例如,153是水仙花数,因为153=1^3+3^3+5^3。请编程计算并输出所有的水仙花数。

输入

输出

所有水仙花数(用空格间隔)

#include <iostream>
using namespace std;
int main() 
{
	for(int i=100; i<=999; i++) 
	{
		int a,b,c;
		a=i%10;//个位
		b=i/10%10;//十位
		c=i/100;//百位
		if(a*a*a+b*b*b+c*c*c==i) 
		{
			cout<<i<<" ";
		}
	}
	return 0;
}

posted @ 2022-10-03 18:58  131452lin  阅读(21)  评论(0编辑  收藏  举报