c++ - Sorting digits of an integer -
You are given an integer 51234
(say) to sort a digit of numbers The need to output will be 12345
.
How to do this without using the array?
You can remove each digit using a loop and % 10
You can. From 0 to 9, the external loop can be tested if the points are present. If it exists, then print it.
In pseudo code:
n = for integer // 51234 = 0 to 9 temp = n repeat if floating% 10 = points again print digit / 0 = Edit: Edit: This test shows in GCC that it handles zero and repeated digits: $ Include cat sortdigits.c # & lt; Stdio.h & gt; Main () {int n, number, floating; N = 43042025; If (temp% 10 == points) for printf ("% d", for digits) (for points = 0; numerals; 9; numeral ++) (temp = n; temp> 0; temp / = 10); Printf ("\ n"); } $ ./sortdigits 00223445
Comments
Post a Comment