You are given an integer 51234 (say) we need to sort the digits of a number the output will be 12345.
How to do it without using array ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use a loop and
% 10to extract each digit.An outer loop from 0 to 9 could be used to test if the digit exists. If it exists, print it.
In pseudo code:
Edit: This test in gcc shows that it handles zeros and repeated digits: