#include<stdio.h>
int main(){
int a[100],b[10],d=0,e,f,g,h,i,n,x=0,y=0,k=1;
scanf("%d",&a[0]);
while(k!=0){
for(e=0;e<d;e++){
if(a[e]==a[d]){
printf("%d\n",d);
for(e=0;e<d;e++)
printf("%d\n",a[e]);
k=0;
}
}
d++;
n=a[d-1];
for(f=0;f<10;f++)b[f]=0;
while(n>0){
b[n%10]++;
n/=10;
}
g=0;
for(f=9;f>=0;f--)
for(h=0;h<b[f];h++)
g=g*10+f;
n=a[d-1];
for(f=0;f<10;f++)b[f]=0;
while(n>0){
b[n%10]++;
n/=10;
}
h=0;
for(f=0;f<=9;f++)
for(i=0;i<b[f];i++)
h=h*10+f;
a[d]=g-h;
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: