Bermudez C Chapter 5 P 2: No use of arrays or loops for ascending order

Viewed 55

Going through Bermudez's C Programming Tutorial (supplement to KN King's book), and perplexed by the second question of Chapter 5 (Selection Statements).

The problem is as follows: write a program that will read in five values and write them out in ascending order.

The very budding programmer is not allowed to use arrays or loops. The only available tools are "if" and "switch" statements.

Here is my issue: I solved the problem by brute force--it's super inelegant. One guess is that I am supposed to feel upset about this exercise; that is, maybe Bermudez wants to show the reader that one needs to do 5! permutations when solely relying on "if" and/or "switch" statements.

Another guess (and probably the more likely one) is that I am doing something really wrong. Something tells me I can cut this code at least in half.

Any suggestions?

3 Answers
Related