#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;
}
原文:https://www.cnblogs.com/2018jason/p/13061741.html