Extra Credit
Extra Credit
Extra credit
4/2/2012
/******************************************************************************
** Class : CIS121-100
** Assignment : Extra Credit - Design a program to print a pyramid
** Name : Vijal Patel
** Student Id : 0619279
** Date : 04/02/2012
******************************************************************************/
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
int triangle( int range)
{
// limiting values for triangle. If value is less than 0 and greater than 20 , the
program will exit
if (range < 1 || range > 20 )
{
exit(0);
}
else (range > 0 || range <= 20);
{
for (int row = 0; row <= range; row++)
{
cout <<"\t\t";
for(int space=range-row; space > 0; space--)
{
cout<<" ";
}
for (int col = 1; col<=row ; col++)
{
cout << "* ";
}
cout << endl; // end the line.
}
}
}
int main()
{
int R;
{
// for triangle the value range is 1 to 20......
cout <<
"\n=============================================================\n";
cout << "\nPlease enter the size range you want between 0 to 20 : ";
cin >> R;
cout << "\n=============================================================\n";
//taking triangle from recursive function
cout << "\n\n" << triangle(R) << endl;
}
_getch();
return 0;
}
Vijal Patel
Extra credit
=============================================================
Please enter the size range you want between 0 to 20 : 9
=============================================================
*
**
***
****
*****
******
*******
********
*********
4/2/2012