Created
February 22, 2020 18:08
-
-
Save illustris/a1091e93ce529a4828ac149a4af303fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define N 4 | |
int *sort(int *arr, int len) | |
{ | |
for(int i=0;i<len;i++) | |
{ | |
for(int j=i+1;j<len;j++) | |
{ | |
if(arr[i]>arr[j]) | |
{ | |
int tmp=arr[i]; | |
arr[i]=arr[j]; | |
arr[j]=tmp; | |
} | |
} | |
} | |
} | |
int main() | |
{ | |
int in,last; | |
int ar[N]; | |
scanf("%d",&in); | |
do | |
{ | |
last=in; | |
int big=0; | |
int small=0; | |
for(int i=0;i<N;i++) | |
{ | |
ar[i]=in%10; | |
in/=10; | |
} | |
sort(ar,N); | |
for(int i=0;i<N;i++) | |
{ | |
big*=10; | |
big+=ar[N-1-i]; | |
small*=10; | |
small+=ar[i]; | |
} | |
in=big-small; | |
printf("%d\n",in); | |
} while(in != last); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment