• June 12, 2021

PHSARIT

Bring Technology Ideas with you

 C++ programming to print Triangle

Printing shapes are one of the most favorite C++ programming for programmers to write; however, in order to know this example, you need to have basic knowledge of:

  • Control Statement
  • Loop statement using C++

For example, you want to print this:

*
* *
* * *
* * * *
* * * * *

Below is the sample code below:

#include<iostream>
using namespace std;
int main() 
{
	int lenght;
	cout << "Please enter the number:" << endl;
	cin >> lenght;
	char Symbol;
	cout << "Please enter the sign:" << endl;
	cin >> Symbol;

	for ( int i = 1; i <= lenght; i++) {
		for (int j = 1; j <= i; j++)
		{
			cout << Symbol;
		}
		cout << endl;
	}

	system("pause>0");

}

The result after execution the code the above:

    Related post