#include <stdio.h>

int main() {
    int x[5],y[5],z[5];
    int a,b,p=1,m,n,o=0,s;
    for(int i=0;i<4;i++)
    {
        scanf("%1d",&x[i]);
        y[i]=x[i];
        z[i]=x[i];
    }
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            if(y[i]>y[j])
            {
                b=y[i];
                y[i]=y[j];
                y[j]=b;
            } 
            if(z[i]<z[j])
            {
                a=z[i];
                z[i]=z[j];
                z[j]=a;
            }
        }
    }
    for(int i=0;i<4;i++)
    {
        m+=y[i]*p;
        n+=z[i]*p;
        p*=10;
    }
    s=o;
    o=m-n;
    printf("%d",o);
}

Embed on website

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