Lab 16
Stars
Objective
To explore nested for loops and the use of the index variable.
Assignment
Read the following code carefully. In the box, write out what you predict the output will be.
#include <iostream>
using namespace std;
int main()
{
int row, col;
cout << endl;
for(row = 0; row < 5; row++)
{
for(col = row; col >= 0; col --)
cout << "*";
cout << endl;
}
return 0;
}
Type in and run the code to see if you were right.
Now, write a C++ program that will generate the
following patterns. Note that you must use for
loops and may not use any if statements! Each of
the designs should be implemented in a separate
function or functions.
*****
****
***
**
*
*
**
***
****
*****
*
***
*****
*******
*********
For the following pattern you may use if
statements, but you may not simply output the text
of the pattern using cout.
*******
** ** (Note: This pattern is
* * * * a square.)
* * *
* * * *
** **
*******
Modify each function to accept a single integer parameter N and draw your patterns to a height of N rows.