The Inverse Pyramid

Two things that seem to be difficult for a beginning C programmer are numbers and their formatted presentation. I admit: These things are difficult to understand. Therefore some practice is in order.

This month’s exercise involves multiple aspects of the C language. Your task is to create an inverse pyramid of numbers that looks like this:

0000000000
999999999
88888888
7777777
666666
55555
4444
333
22
1

To create this output, look in your C language tool chest and pull out the following items:

  1. A loop.
  2. Another loop! (A nested loop.)
  3. Math necessary.

Obviously, the code needs to count down from 10 to 1. The problem, of course, is how to display that initial line of ten zeros and not ten 10s. That’s the math necessary part.

A number of ways exist to solve this puzzle. Click here to read about my solution.