c语言编程练习题:7-44 黑洞数
作者:yunjinqi   类别:    日期:2023-05-29 15:57:17    阅读:442 次   消耗积分:0 分    


image.png



#include <stdio.h>

int main(){
    int num=0,a,b,c,max_num,min_num,i,j,res;
    int num_array[6];
    res = scanf("%d",&num);
    if (res!=EOF){
        for (i=0;num!=495||i==0;i++){
            a = num/100;
            b = (num-100*a)/10;
            c = num-100*a-10*b;
            //printf("a=%d b=%d c=%d\n",a,b,c);
            num_array[0] = a*100+b*10+c;
            num_array[1] = a*100+c*10+b;
            num_array[2] = b*100+a*10+c;
            num_array[3] = b*100+c*10+a;
            num_array[4] = c*100+b*10+a;
            num_array[5] = c*100+a*10+b;
            max_num=0;
            min_num=1000;
            for (j=0;j<6;j++){
                //printf("num_array[%d] = %d ",j,num_array[j]);
                if (max_num<num_array[j]){max_num=num_array[j];}
                if (min_num>num_array[j]){min_num=num_array[j];}
            }
            num = max_num - min_num;
            printf("%d: %d - %d = %d\n",i+1,max_num,min_num,num);
            //if (num==495){break;}

        }
    }else{
        printf("num input wrong");
    }
    return 0;
}


版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/169
上一篇:c语言编程练习题:7-43 Shuffling Machine
下一篇:c语言编程练习题:7-45 找完数