# Thread: How to make greatest 3 digit number from given number

1. ## How to make greatest 3 digit number from given number

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,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
thanks 2. I think very confusing variable naming convention n and no. It gets struck in while loop i suppose. 3. A development process

Step 1 - input a number (say 57149) and output say
found 5
found 7
found 1
found 4
found 9

Step 2 - increment count[x] for each digit found.

Step 3 - solve the problem. 4. Originally Posted by Salem A development process

Step 1 - input a number (say 57149) and output say
found 5
found 7
found 1
found 4
found 9

Step 2 - increment count[x] for each digit found.

Step 3 - solve the problem.
Very good hint at a simple solution.
I was thinking sorting solution; but, using an count[x] array is must simpler.

Tim S. Popular pages Recent additions #include, digits, int, number, user 