Write a C++ program to print the right angled triangle of alphabets pattern using for loop.
#include<iostream> using namespace std; int main() { int i, j, alphabet, rows; cout << "Enter Right Triangle Alphabets Pattern Row = "; cin >> rows; cout << "Right Angled Triangle Alphabets Pattern\n"; alphabet = 65; for(i = 0; i < rows; i++) { for(j = 0; j <= i; j++) { cout << char(alphabet + j) << " "; } cout << "\n"; } return 0; }
This C++ example prints the alphabets in the right angled triangle pattern using a while loop.
#include<iostream> using namespace std; int main() { int i = 0, j, alphabet, rows; cout << "Enter Right Triangle Alphabets Pattern Rows = "; cin >> rows; cout << "Right Angled Triangle Alphabets Pattern\n"; alphabet = 65; while(i < rows) { j = 0; while( j <= i) { cout << char(alphabet + j) << " "; j++; } cout << "\n"; i++; } return 0; }
Enter Right Triangle Alphabets Pattern Rows = 16
Right Angled Triangle Alphabets Pattern
A
A B
A B C
A B C D
A B C D E
A B C D E F
A B C D E F G
A B C D E F G H
A B C D E F G H I
A B C D E F G H I J
A B C D E F G H I J K
A B C D E F G H I J K L
A B C D E F G H I J K L M
A B C D E F G H I J K L M N
A B C D E F G H I J K L M N O
A B C D E F G H I J K L M N O P