判断一个数是否为"水仙花数",所谓"水仙花数"是指这样的一个数:首先是一个三位数,其次,其各位数字的立方和等于该数本身。例如:371是一个"水仙花数",371=33+73+1^3.
#include<stdio.h>
#include<string.h>
#include<math.h>
// int Isnarc(int n){
// int a,b,c;
// a = n/100; //百位
// b = n/10%10; //十位
// c = n%10; //个位
// if(n == (pow(a,3)+pow(b,3)+pow(c,3))) return 1;
// else return 0;
// }
int Isnarc(int n){
int sum=0,temp=n;
while(temp){
sum += pow(temp%10,3);
temp = temp/10;
}
return sum==n;
}
int main(){
int n;
scanf("%d",&n);
printf("%d\n",Isnarc(i));
return 0;
}