//*************************************************************
// File: asterisk.cpp
// Name: DMN
// Project or HW or Lab name: HW example
/* Description: - A program that uses nested
for loops
to generate a
right triangle with n asterisks such
that the first row has one asterisk, the second
has two,
and so on, with the asterisks right-aligned on
each row
such as the following for n=5. Program should be able to
n in the range of 1..20.
*
**
***
****
*****
*/
//*********************************************************************
#include <iostream>
using namespace std;
int main()
{
int
num_rows, row, index;
cout << "How many
rows (1-20): ";
cin >> num_rows;
for (row=1; row<=num_rows; row++)
{
// indent by
printing (num_rows-row) spaces
for (index=1; index<=num_rows-row; index++)
{
cout << ' ';
}
// print row
asterisks
for (index=1; index<=row; index++)
{
cout << '*';
}
// drop cursor to a new line
cout << endl;
} // end for (row. . .
return 0;
} // end main
syntax highlighted by Code2HTML, v. 0.9.1