← Back to If Statements
Question 248
Sort Three Numbers
Sort Three Numbers
Three numbers are stored in the variables a, b and c (declared with let). Using only if statements and swaps, rearrange the values so that a holds the smallest, b the middle and c the largest, then print them on one line separated by single spaces. Three compare-and-swap steps are enough: compare a with b, then a with c, then b with c. A swap needs a temporary variable.
Expected Output:
2 5 9= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
If Statements
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (clog, fn, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.