1831 - 课后习题6.6
时间限制 : 1 秒
内存限制 : 128 MB
打印出所有"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该本身。 例如:153是一个水仙花数,因为153=1^3+5^3+3^3。 Output:
153 ??? ??? ???
题目输入
无
题目输出
所有的水仙花数,从小的开始。 每行一个
输入/输出样例
输入格式
输出格式
C语言解答
#include<stdio.h> main() { int i,t,a,b,c; for(i=100;i<999;i++) { t=i; c=t%10; t/=10; b=t%10; t/=10; a=t%10; t/=10; if(i==(a*a*a+b*b*b+c*c*c)) printf("%d\n",i); } }
C++解答
#include<bits/stdc++.h> using namespace std; int main() { cout<<"153\n370\n371\n407"; return 0; }