输出所有的“水仙花数”。所谓的“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如153就是一个水仙花数,下面让我们来证明一下它吧!
#include<stdio.h>//头文件 #include<math.h>//数学函数 int main()//主函数 { int a, b, c, n;//声明变量 printf("请输入一个水仙花数:");//水仙花数是指一个三位数 scanf_s("%d", &n);//&占位符也相当于输入一个整型变量n a = n / 100;//求出百位数字 b = n % 100 / 10;//求出十位数字 c = n % 10;//求出个位数字 if (n == pow(a, 3) + pow(b, 3) + pow(c, 3))//运用数学函数必须加上头文件数学函数math.h { printf("此数字%d是水仙花数", n); } else { printf("此数字%d不是水仙花数,是一个单纯的整数", n); } return 0;//返回主函数 }
05-16
1189