杭电OJ-水仙花数

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n,m;
    int array[1000];
    int a,b,c;
    int p=1,d;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        d=0;
        if(n>m)
        {
            int temp;
            temp=n;
            n=m;
            m=temp;
        }
        int i;
        for(i=n; i<=m; i++)
        {
            a=i%10;//个位
            b=i/10%10;//十位
            c=i/100;//百位
            if(a*a*a+b*b*b+c*c*c==i)
            {
                array[d]=i;
                d++;
                //p=0;
            }
        }
        if(d==0)
        {
            printf("no\n");
        }
        else
        {
            for(i=0;i<d;i++)
            {
                if(i!=d-1)
                {
                    printf("%d ",array[i]);
                }
                else
                {
                    printf("%d\n",array[i]);
                }

            }
        }
        //printf("\n");
    }
    return 0;
}
 

猜你喜欢

转载自blog.csdn.net/qq_38587650/article/details/89077784
今日推荐