#include<stdio.h>
#include<stdlib.h>
int Ascending(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
}
int main()
{
int N;
scanf("%d", &N);
int figures[5];
int i = 0 , j;
do
{
i=0;
for(i=0;i<4;i++)
{
figures[i] = N % 10;
N = N/10;
}
qsort(figures, 4, sizeof(figures[0]), Ascending);
int A=0, B=0;
for(i=3;i>=0;i--)
A = A*10 + figures[i];
for(i=0;i<4;i++)
B = B*10 + figures[i];
N = A - B;
printf("%04d - %04d = %04d\n", A, B, N);
if(N == 0)
break;
}while(N != 6174);
}
网友评论