编程小白,写了一题,结果不对求指教

水仙花问题
输出100到999的所有水仙花数
ABC=A^3+B^3+C^3
如153=1^3+5^3+3^3
#include
#include
int main()
{
int i,A,B,C;
for(i=100;i<=999;i++)
{

        C=i%10;
        B=C%10;
        A=B%10;
        if(i==pow(A,3)+pow(B,3)+pow(C,3))
            printf("%d",i);

 } 

}

我在你的代码基础上改了一些:
#include
#include
int main()
{
int i, A, B, C;
for (i = 100; i <= 999; i++)
{

    C = i / 100; //百位数
    B = i /10 % 10; //十位数
    A = i % 10;//个位数
    if (i == pow(A, 3) + pow(B, 3) + pow(C, 3))
        printf("%d ", i);
}

}

昨天我也做了这个题,不过是用python写的
def sxh(n):

g=n%10
b=n//100
s=int(str(n)[1])

if n==g**3+s**3+b**3:return 1

sxhList=[]
for i in range(100,1000):
if sxh(i) ==True:sxhList.append(i)

print(sxhList)
print("三位水仙花数量共有{}个。".format(len(sxhList)))

//一个三位数若其各位数字立方和等于该数本身,则为水仙花数

#include <stdio.h>
#include <math.h>
int main()
{
    int a, b, c, i;

    for (i = 100; i < 1000; i++)
    {
        if (i == pow(i / 100 % 10, 3) + pow(i / 10 % 10, 3) + pow(i % 10, 3))
            printf("%d\n", i);
    }


    return 0;
}

#include
#include
int shuixianhua(int m);
int main()
{
int i,n,j;
scanf("%d",&n); /* n位整数*/
int sum=1,sum1=1;
for(i=1;i<=n;i++)
sum=sum*10;
for(i=1;i<=n-1;i++)
sum1=sum1*10;
for(i=sum1;i<=sum-1;i++){
if(shuixianhua(i)!=0)
printf("%d\n",i);
}
return 0;
}
int shuixianhua(int m)
{
int x,h,sum2=0;
int count=0;
h=m;
while(h>0){
count++;
h=h/10;
}
int j,k=1,g;
j=m;
while(m>0){
x=m%10;
for(g=1;g<=count;g++){
k=k*x;}
sum2=sum2+k;
k=1;
m=m/10;
}
if(j==sum2) return 1;
else return 0;
}
楼主可以看一下 ,类似题目,求n位水仙花数