topic description
Print out all "Narcissus Numbers". The so-called "Daffodils Number" refers to a three-digit number, and the sum of the cubes of each digit is equal to itself. For example: 153 is a daffodil number, because 153=1^3+5^3+3^3.
enter
none
output
Output the number of each daffodil, one number occupies one line
#include<stdio.h>
int main()
{
int n=3; //三位数以内
int first = 1;
int i = 1;
while (i < n)
{
first *= 10;
i ++;
}
i = first;
while(i < first*10)
{
int t =i;
int sum = 0;
do{
int d= t %10;
t /= 10;
int p = d;
int j = 1;
while(j < n)
{
p *= d;
j++;
}
sum += p;
}while(t > 0);
if(sum == i)
printf("%d\n",i);
i++;
}
return 0;
}