2013年11月8日 星期五

C++之水仙花數



#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d,e;
for(a=1;a<9;a++)
{
     for(b=0;b<9;b++)
     {
for(c=0;c<9;c++)
{
d=c*c*c+b*b*b+a*a*a;
e=100*a+10*b+c;
if(d==e)
cout<<e<<endl;
}
     }

}
system("pause") ;
}
水仙花數是每個位數的立方為自身的三位數,例如:153=3*3*3+5*5*5+1*1*1

沒有留言:

張貼留言