水仙花数

 

#include <iostream>
using namespace std;
int main( )
{  

  int n,a,b,c;
     for (a=1; a<=9;a++)
         for (b=0; b<=9; b++)
              for (c=0; c<=9; c++)
         {   

n=a*100+b*10+c;

 if (n==a*a*a+b*b*b+c*c*c)             cout<<n<<endl;
       } 
       system("pause");

   return 1;
}

 

 

#include <iostream>
using namespace std;
int main( )

int i,a,b,c;


 for (i=100; i<=999; i++)
 {

 

 a=i/100; 

b=i/10%10; 

c=i%10;
  if (a*a*a+b*b*b+c*c*c==i)           cout<<i<<endl;
 }
 system("pause"); return 1;

 

posted @ 2014-07-26 20:24  博园少主  阅读(119)  评论(0编辑  收藏  举报