水仙花数
程序员文章站
2024-03-17 16:26:10
...
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int Judge (int m);
int findArray();
int main ()
{
int num = 0;
num=findArray();
printf("水仙花数个数为%d个。\n",num);
system("pause");
return 0;
}
int findArray()
{
int i,count = 0;
for( i = 100 ; i <= 999 ; i++ )
if(Judge (i))
{
count+=1;
printf("水仙花数是%d\n",i);
}
return count;
}
int Judge(int m)
{
int x,y,z;
x = m/100;
y = m%100/10;
z = m%10;
if( ( pow(x,3) + pow (y,3) +pow(z,3)) == m)
return 1;
else
return 0;
}
上一篇: 汉诺塔(hanoi)-递归实现
下一篇: Python函数进阶