Given a positive integer less than 10,000, write a C program that will find the largest possible number that can be formed by rearranging the digits of the number.
Example:
If i input: 2594
The program must output: 9542
This is my program and i don't know where's my error about printing the output. Can anyone help me?
Code:
#include <stdio.h>
#include <math.h>
char a[4],temp;
int x,y,totl;
main() {
clrscr();
printf("Input: ");
scanf("%s",a);
for(x=0;x<4;x++) {
for(y=x;y<4;y++) {
if(a[x]<a[y]) {
temp=a[x];
a[x]=a[y];
a[y]=temp;
}
}
}
printf("Output: %c\n",a);
getch(); }