Skip to content

Instantly share code, notes, and snippets.

Created March 14, 2018 13:34
Show Gist options
  • Save anonymous/37da98d56f71ba62df6ecd96adef6620 to your computer and use it in GitHub Desktop.
Save anonymous/37da98d56f71ba62df6ecd96adef6620 to your computer and use it in GitHub Desktop.
SortDigits F
#include <stdio.h>
int F(int N){
int d1, d2, temp;
if (N<10) return N;
else
{
d1=N%10;
N=N/10;
N=F(N);
d2=N%10;
if (d1<=d2) return N*10+d1;
else
{
N=((N/10)*100) + (d1*10) + d2;
temp=F(N/10);
return (temp*10) + (N%10);
}
}
}
void main()
{
int n = 23989769;
printf("Fix number: %d\n", F(n));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment