0% found this document useful (0 votes)
29 views2 pages

Extra Credit

Vijal Patel wrote a C++ program to print a pyramid shape with asterisks based on a user-input number between 1-20. The program defines a triangle function that prints the pyramid, with rows of asterisks adding one more asterisk as the row number increases. It prompts the user to enter a number, calls the triangle function to print the pyramid shape of that size, and ends the program.

Uploaded by

Vijal Patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Extra Credit

Vijal Patel wrote a C++ program to print a pyramid shape with asterisks based on a user-input number between 1-20. The program defines a triangle function that prints the pyramid, with rows of asterisks adding one more asterisk as the row number increases. It prompts the user to enter a number, calls the triangle function to print the pyramid shape of that size, and ends the program.

Uploaded by

Vijal Patel
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Vijal Patel

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

You might also like