#include <stdio.h>
#include<string.h>
void high(int x[],int z,int y)
{
    int a=0,p=0,q=0,b=0,r=1;
    for(int i=0;i<z;i++)
    {
        for(int j=0;j<z;j++)
        {
            if(x[i]>x[j])
            {
                a=x[i];
                x[i]=x[j];
                x[j]=a;
            } 
        }
    }
    for(int i=0;i<z;i++)
    {
        p+=x[i]*r;
        r=r*10;
    }
    for(int i=0;i<z;i++)
    {
        for(int j=0;j<z;j++)
        {
            if(x[i]<x[j])
            {
                b=x[i];
                x[i]=x[j];
                x[j]=b;
            } 
        }
    }
    r=1;
    for(int i=0;i<z;i++)
    {
        q+=x[i]*r;
        r=r*10;
    }
    y=q-p;       
}
int main() {
    char a[10000];
    int b[10000];
    int x,y,z;
    scanf("%s",a);
        z=strlen(a);
        for(int i=0;i<z;i++)
        {
            b[i]=a[i]-'0';
        }
        high(b,z,y);
    printf("%d",y);
}

Embed on website

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