CS110 Lab: Nested Loops

In-lab Exercise

Write a C++ program to print out an upside down triangle of stars to the screen.
The user will enter the number of stars in the first line. For example:
      How many stars on the first line? 5

      *****
      ****
      ***
      **
      *

Tip: this is a loop nesting exercise. Try starting with a counting for loop that counts down from the number the user entered to 1 like this:

      How many stars on the first line? 5
      5
      4
      3
      2
      1

then add an inner loop that can print that many stars on one line.


This page last modified:
Monday, 29-Feb-2016 10:24:39 CST
Accessed     times.

Copyright: Department of Computer Science, University of Regina.