please help me i m making program which takes a number from user and then make greates 3 digit number from the digits of that number
ex. if user type 57149 then output should be 975 because this is the greatest number that can be formed by digits. i tried below code but when i type number nothing is shown
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[20],n,no,i,cnt=0;
printf("Enter a no.");
scanf("%d",&no);
n=no;
while(no!=0)
{
no=n/10;
cnt++;
}
for(i=0;i<cnt;i++)
{
a[i]=n%10;
n=n/10;
if(n==0)
break;
}
for(i=0;i<cnt;i++)
printf("%d\n",a[i]);
return 0;
}
above program even not printing the digits of number. so i didnt type further but once i get code to separate digits i will sort the array and will print first 3 numbers because we want 3 digit largest number
but first someone correct this code so it can separate digits please help me
thanks