/*C语言的"水仙花数"实现代码*/
#include
#include
#include
int cube ( const int n )
{
return n * n * n;
}
bool isNarcissistic ( const int n )
{
int hundreds = n / 100;
int tens = n / 10 - hundreds * 10;
int ones = n % 10;
return cube(hundreds) + cube(tens) + cube(ones) == n;
}
int main(void)
{
int i;
for ( i = 100; i < 1000; ++ i )
{
if ( isNarcissistic(i) )
printf("%d\n", i );
}
return EXIT_SUCCESS;
}