#include <stdio.h>
#include <math.h>
bool sxhs(int n)
{
int a,b,c;
a=n/100; //取出n百位上的数字
b=n/10%10; //取出n十位上的数字
c=n%10; //取出n个位上的数字
if(pow(a,3)+pow(b,3)+pow(c,3)==n) //pow(a,3) 等价于求a的三次方
{
return true;
}
else
{
return false;
}
}
main()
{
for(int i=100;i<1000;i++)
{
if(sxhs(i))
{
printf("%d\t",i);
}
}
printf("\n");
}
求水仙花数
最新推荐文章于 2020-10-25 11:17:42 发布