#include<stdio.h>
int main()
{
    int a,b,c,d,f,h,o,m=0,e=1,l=0,v=0,k=1,u=0,q;
    int x[1000],y[1000],z[1000];
        scanf("%d",&a);
        v=0;
      int s=0;
    while(k!=0)
        {
    for(h=0;0<a;h++)
    {
        x[h]=(a%10);
        a/=10;
        y[h]=x[h];
    }
    for(int i=0;i<h-1;i++)
    {
        for(int j=i;j<h;j++)
        {
            if(x[i]<x[j])
            {
                o=x[i];
                x[i]=x[j];
                x[j]=o;
            }
        }
    }
    for(int i=0;i<h;i++)
    {
        m+=(x[i]*e);
        e*=10;
    }
    for(int i=0;i<h-1;i++)
    {
        for(int j=i;j<h;j++)
        {
            if(y[i]>y[j])
            {
                o=y[i];
                y[i]=y[j];
                y[j]=o;
            }
        }
    }
    e=1;
    for(int i=0;i<h;i++)
    {
        l+=(y[i]*e);
        e*=10;
    }
    z[v++]=l-m;
    a=z[v++];
    l=0;
    m=0;
    e=1;
    for(q=1;q<v;q++)
    {
        if(z[q]==z[v] && q!=v)
        {
            k=0;
        }
    }
    }
     printf("%d\n",z[s]);
    s++;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: