#include <stdio.h>
bool isRoseNumber(int num);
int main()
{
for(int i = 1000; i < 10000; i++)
{
if(isRoseNumber(i)){
printf("%d is rose number.\n", i);
}
}
return 0;
}
bool isRoseNumber(int num)
{
int a, b, c, d;
a = num / 1000;
b = (num / 100) % 10;
c = (num / 10) % 10;
d = num % 10;
return ((a * a * a * a + b * b * b * b + c * c * c * c + d * d * d * d) == num);
}
结果如下:
1634 is rose number.
8208 is rose number.
9474 is rose number.
Press any key to continue
网友评论