Write a C++ program to print inverted right triangle alphabets pattern using for loop.
#include<iostream> using namespace std; int main() { int rows; cout << "Enter Inverted Right Triangle of Alphabets Rows = "; cin >> rows; cout << "Printing Inverted Right Triangle Alphabets Pattern\n"; int alphabet = 65; for (int i = rows - 1; i >= 0; i--) { for (int j = 0; j <= i; j++) { cout << char(alphabet + j); } cout << "\n"; } }
C++ program to print inverted right triangle alphabets pattern using a while loop.
#include<iostream> using namespace std; int main() { int rows, i, j, alphabet; cout << "Enter Inverted Right Triangle of Alphabets Rows = "; cin >> rows; cout << "Printing Inverted Right Triangle Alphabets Pattern\n"; alphabet = 65; i = rows - 1; while (i >= 0) { j = 0; while (j <= i) { cout << char(alphabet + j); j++; } cout << "\n"; i--; } }
Enter Inverted Right Triangle of Alphabets Rows = 14
Printing Inverted Right Triangle Alphabets Pattern
ABCDEFGHIJKLMN
ABCDEFGHIJKLM
ABCDEFGHIJKL
ABCDEFGHIJK
ABCDEFGHIJ
ABCDEFGHI
ABCDEFGH
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A
This C++ example prints the inverted right angled triangle pattern of alphabets using a do while loop.
#include<iostream> using namespace std; int main() { int rows, i, j, alphabet; cout << "Enter Inverted Right Triangle of Alphabets Rows = "; cin >> rows; cout << "Printing Inverted Right Triangle Alphabets Pattern\n"; alphabet = 65; i = rows - 1; do { j = 0; do { cout << char(alphabet + j); } while (++j <= i); cout << "\n"; } while (--i >= 0); }
Enter Inverted Right Triangle of Alphabets Rows = 17
Printing Inverted Right Triangle Alphabets Pattern
ABCDEFGHIJKLMNOPQ
ABCDEFGHIJKLMNOP
ABCDEFGHIJKLMNO
ABCDEFGHIJKLMN
ABCDEFGHIJKLM
ABCDEFGHIJKL
ABCDEFGHIJK
ABCDEFGHIJ
ABCDEFGHI
ABCDEFGH
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A