Code:
/**********************************************************************
** CSC 213 **
** Lab - 3 **
** Author: Felipe Fuentealba **
** **
** Source File Lab3.cpp from page 165, exercise 2.47 **
** **
** Description - Write a program that uses for structures to **
** print the following patters separately, one **
** bellow the other. Use for loops to generate **
** the patters separately. All asterisks (*) should **
** be printed by a single statement of the form **
** cout << '*'; ( this causes the asterisks to print **
** side by side). [Hint: The last two patterns **
** require that each line begin with an apropiate number **
** of blanks. **
** **
** * **
** ** **
** *** **
** **** **
** ***** **
** ****** **
** ******* **
** ******** **
** ********* **
** ********** **
** **
** The Second Loop - creates a variable for the loop, **
** intalize it to 1, and it is a int type **
** variable, nStarCounter < (nLineCounter+1) **
** means loop until the nStartCounter is **
** less then linecounter + 1 so on the first line **
** it will loop 1 time cause line counter + 1 == 2 **
** and if it loops around star counter will be 2 **
** and its not less then 2. **
** The fineal part of the for nStarCounter++ **
** means when the loop has finished, increment **
** nStarcounter by 1 **
** **
**********************************************************************/
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(int nNumbofArgs, char* pszArgs[])
{
for ( int nLineCounter = 1; nLineCounter <= 10; nLineCounter++ ){
for ( int nStarCounter = 1; nStarCounter < (nLineCounter+1); nStarCounter++ ){
cout << '*';
}
// one is a line feed the other is a carrage return
cout << '\r'; // \r means move to start of the line
cout << '\n'; // \n means go down one spot
}
// wait until user is ready before terminating program
// to allow the user to see the program results
system("PAUSE");
return 0;
}