首页 > 其他 > 详细

实验4-1-12 黑洞数

时间:2020-06-07 22:05:39      阅读:72      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>

int max(int a, int b);
int min(int a, int b);
int main(void)
{
    int num, a, b, c;
    int t, maxNum, midNum, minNum;
    int big, small, i;

    scanf("%d", &num);

    i = 1;
    do
    {
        //分离百十个
        a = num / 100;
        b = num % 100 / 10;
        c = num % 10;
        t = a + b + c;

        maxNum = max(max(a, b), c);
        minNum = min(min(a, b), c);
        midNum = t - maxNum - minNum;

        big = maxNum * 100 + midNum * 10 + minNum;
        small = minNum * 100 + midNum * 10 + maxNum;
        num = big - small;

        printf("%d: %d - %d = %d\n", i, big, small, num);

        i++;
    } while (num != 495);

    return 0;
}

int max(int a, int b)
{
    int ret = a;
    if (b > a)
    {
        ret = b;
    }

    return ret;
}

int min(int a, int b)
{
    int ret = a;
    if (b < a)
    {
        ret = b;
    }

    return ret;
}

实验4-1-12 黑洞数

原文:https://www.cnblogs.com/2018jason/p/13061741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!