C语言的学习过程,我把它记录下来 | |
---|---|
水仙花数是指一N位数,其各个数之N次方和等于该数 | |
如153 = 1^3 + 5^3 + 3^3 |
#include<stdio.h>
#include<math.h>
int main()
{
int num1, num2, num3, temp;
for (temp = 0; temp <= 999; temp++)
{
num1 = temp % 10; //取余求出个位数数字
num2 = (temp % 100 - num1)/10; //取余求出十位数数字
num3 = (temp % 1000 - num2 - num1)/100; //取余求出百位数数字
if (temp == pow(num1, 3) + pow(num2, 3) + pow(num3, 3))//pow用来求x的y次幂,引用math.h
{
printf("%d ", temp);
}
}
return 0;
}
希望能和大家一起学习、进步,每一个关注和点赞都是我学习的动力,我也会回关回赞的,互相督促共同进步 |
---|