Lesson 4
Repeated Practice Makes Perfect
Chapter 3: While loops
Triangle of stars
Now, let us do some practical exercises to make sure that you really understand while
loops.
Write a program that reads in an integer rows
from the user.
Then, use a while loop to automatically print out a triangle of stars of height rows
.
For example, the following output is expected for rows = 5
.
Enter an integer: 5
*
**
***
****
*****
And here is the expected output for rows = 8
.
Enter an integer: 8
*
**
***
****
*****
******
*******
********
Remember - think carefully about the algorithm first before jumping into coding!