#include <stdio.h>
bool isNarcissisticNumber(int num);
int main()
{
for(int i = 100; i < 1000; i++)
{
if(isNarcissisticNumber(i)){
printf("%d is narcissistic number.\n", i);
}
}
return 0;
}
bool isNarcissisticNumber(int num)
{
int a, b, c;
a = num / 100;
b = (num / 10) % 10;
c = num % 10;
return ((a * a * a + b * b * b + c * c * c) == num);
}
结果如下:
153 is narcissistic number.
370 is narcissistic number.
371 is narcissistic number.
407 is narcissistic number.
Press any key to continue