输入一个三位数,判断是不是水仙花数(各位数字的立方和等于这个三位数本身)
请各位不吝赐教
#include <stdbool.h> bool foo( unsigned n ) { unsigned a = n/100%10; unsigned b = n/10%10; unsigned c = n/1%10; return n>=100 && n<1000 && a*a*a+b*b*b+c*c*c==n; } bool bar( unsigned n ) { return n==153 || n==370 || n==371 || n==407; }
#include <stdio.h> void main() { int a,i,array[]={153,370,371,407,0}; while(scanf("%d",&a))if(!(a>=0[array]&&a<=array[sizeof(array)/sizeof(int)-2]?i=0:printf("no\n")))for(;i[array];i++,!i[array]?!a?printf("yes\n"):printf("no\n"):0)if(!(i[array]^a))a=0; }
#include <stdio.h> int main() { int a, b, c, x; printf("请输入一个三位数:"); scanf("%d", &x); //输入值设为x if (100 <= x && x <= 1000) { a = x / 100; //a为x的百位数 b = x / 10 % 10; //b为x的十位数 c = x % 10; //c为x的个位数 if (a * a * a + b * b * b + c * c * c == x) { printf("yes\n"); } else { printf("no\n"); } } else { printf("输入错误!\n"); //提醒非三位数的错误输入 } return 0; }