[go: up one dir, main page]

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

Print Triangle Patterns in C++

The document provides two examples of C++ programs that print triangles using asterisks. The first example creates a half-pyramid based on user-defined rows, while the second example generates an inverted half-pyramid. Each example includes the source code necessary to execute the programs.

Uploaded by

Bishal Debbarma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Print Triangle Patterns in C++

The document provides two examples of C++ programs that print triangles using asterisks. The first example creates a half-pyramid based on user-defined rows, while the second example generates an inverted half-pyramid. Each example includes the source code necessary to execute the programs.

Uploaded by

Bishal Debbarma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Programs to Print Triangles Using *.

Example 1: Program to Print a Half-Pyramid Using *

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

Source Code
#include <iostream>
using namespace std;

int main() {

int rows;

cout << "Enter number of rows: ";


cin >> rows;

for(int i = 1; i <= rows; ++i) {


for(int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << "\n";
}
return 0;
}

Example 2: Inverted Half-Pyramid Using *

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

Source Code
#include <iostream>
using namespace std;

int main() {

int rows;

cout << "Enter number of rows: ";


cin >> rows;

for(int i = rows; i >= 1; --i) {


for(int j = 1; j <= i; ++j) {
cout << "* ";
}
cout << endl;
}

return 0;
}

You might also like