#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
int n;
scanf ("%d",&n);
int a[3],cnt = 1,t=n;
while (t!=495)
{
int i=0;
while (t)
{
int tt = t%10;
t/=10;
a[i++] = tt;
}
int mx = 0,mn=0;
for (int i=0;i<3;i++)
for (int j=i+1;j<3;j++)
{
if (a[i]<a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
for (i=0;i<3;i++)
mx = mx*10+a[i];
for (int i=0;i<3;i++)
for (int j=i+1;j<3;j++)
{
if (a[i]>a[j])
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
for (i=0;i<3;i++)
mn = mn*10+a[i];
printf ("%d: %d - %d = %d\n",cnt,mx,mn,mx-mn);
cnt++;
t = mx-mn;
}
return 0;
}
实验4-1-12 黑洞数
最新推荐文章于 2024-08-31 15:34:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)