Write a C++ program to print the hollow right angled triangle star pattern using for loop.
#include<iostream> using namespace std; int main() { int i, j, rows; cout << "Enter Hollow Right Triangle Star Pattern Row = "; cin >> rows; cout << "Hollow Right Angled Triangle Star Pattern\n"; for(i = 1; i <= rows; i++) { for(j = 1; j <= i; j++) { if(i == 1 || i == rows || j == 1 || j == i) { cout << "* "; } else { cout << " "; } } cout << "\n"; } return 0; }
This example prints the hollow right angled triangle pattern of a given character using a while loop.
#include<iostream> using namespace std; int main() { int i = 1, j, rows; char ch; cout << "Enter Hollow Right Triangle Star Pattern Row = "; cin >> rows; cout << "Enter Symbol for Hollow Right Triangle Pattern = "; cin >> ch; cout << "Hollow Right Angled Triangle Star Pattern\n"; while(i <= rows) { j = 1; while(j <= i) { if(i == 1 || i == rows || j == 1 || j == i) { cout << ch << " "; } else { cout << " "; } j++; } cout << "\n"; i++; } return 0; }
Enter Hollow Right Triangle Star Pattern Row = 16
Enter Symbol for Hollow Right Triangle Pattern = $
Hollow Right Angled Triangle Star Pattern
$
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $