水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。
代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{int a,b,c,x;
scanf("%d",&x);
a=x/100;
b=(x-a*100)/10;
c=x-a*100-b*10;
if(x==a*a*a+b*b*b+c*c*c)
printf("yes");
else
printf("no");
return 0;
}
输入153 结果:yes