Difficulty: ★ ★ ★ ☆
One of the first lessons taught for any budding programmer is to to output sequential values, say one through ten. I use this example in my books to demonstrate how loops work. You can use for, while, and even goto to make the magic happen in the C language. But can you code such a program without using any looping keywords?
Obviously, if you’re going to write a program that counts from one to ten, a loop is the tool you use. In fact, loops are one of the common, simple parts of any programming language. So this challenge is about thinking beyond the tools you normally use. And, yes, this challenge is solvable.
Your task is to write a program that loops n times without using any C language looping statements: for, while, or goto.
It is not a valid solution to just stack up a bunch of printf() (or similar) statements. The code must somehow repeat on its own to generate the sequential output.
It’s also not valid to insert assembly language code or to call an external program that does the job. No, the code must be self-contained and all C.
Here is output from my solution:
Loop count = 12 1 2 3 4 5 6 7 8 9 10 11 12
The program prompts for input with Loop count =. The user types in a positive, non-zero value. The program generates sequential output from one up to and including the integer value input.
Please try this exercise on your own before you check out my solution, which I’ll post in a week.