Write a C++ program to print the right angled triangle number pattern using for loop.
#include<iostream> using namespace std; int main() { int i, j, rows; cout << "Enter Right Triangle Number Pattern Row = "; cin >> rows; cout << "Right Angled Triangle Number Pattern\n"; for(i = 1; i <= rows; i++) { for(j = 1; j <= i; j++) { cout << i << " "; } cout << "\n"; } return 0; }
This C++ example prints the numbers in the right angled triangle pattern using a while loop.
#include<iostream> using namespace std; int main() { int i = 1, j, rows; cout << "Enter Right Triangle Number Pattern Row = "; cin >> rows; cout << "Right Angled Triangle Number Pattern\n"; while(i <= rows) { j = 1; while( j <= i) { cout << i << " "; j++; } cout << "\n"; i++; } return 0; }
Enter Right Triangle Number Pattern Row = 9
Right Angled Triangle Number Pattern
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9