Write a C++ program to print right triangle of mirrored numbers pattern using for loop.
#include<iostream> using namespace std; int main() { int rows; cout << "Enter Right Traingle Mirrored Numbers Rows = "; cin >> rows; cout << "The Right Traingle of Mirrored Numbers\n"; for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { cout << j << " "; } for (int k = i - 1; k >= 1; k--) { cout << k << " "; } cout << "\n"; } }
C++ program to print the right angled triangle of mirrored numbers pattern using a while loop.
#include<iostream> using namespace std; int main() { int rows, i, j, k; cout << "Enter Right Traingle Mirrored Numbers Rows = "; cin >> rows; cout << "The Right Traingle of Mirrored Numbers\n"; i = 1; while (i <= rows) { j = 1; while (j <= i) { cout << j << " "; j++; } k = i - 1; while (k >= 1) { cout << k << " "; k--; } cout << "\n"; i++; } }
Enter Right Traingle Mirrored Numbers Rows = 9
The Right Traingle of Mirrored Numbers
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
This C++ example displays the right angled triangle pattern of mirrored numbers using the do while loop.
#include<iostream> using namespace std; void rtMirroredColumnNumbers(int rows) { for (int i = 1; i <= rows; i++) { for (int j = 1; j <= i; j++) { cout << j << " "; } for (int k = i - 1; k >= 1; k--) { cout << k << " "; } cout << "\n"; } } int main() { int rows; cout << "Enter Right Traingle Mirrored Numbers Rows = "; cin >> rows; cout << "The Right Traingle of Mirrored Numbers\n"; rtMirroredColumnNumbers(rows); }
Enter Right Traingle Mirrored Numbers Rows = 13
The Right Traingle of Mirrored Numbers
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 5 6 5 4 3 2 1
1 2 3 4 5 6 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 2 1