C++ Program to Print Triangle of Mirrored Numbers Pattern

Write a C++ program to print triangle of mirrored numbers pattern using for loop.

#include<iostream>
using namespace std;

int main()
{
	int rows;

	cout << "Enter Traingle Mirrored Numbers Rows = ";
	cin >> rows;

	cout << "Printing Traingle of Mirrored Numbers Pattern\n";

	for (int i = 1; i <= rows; i++)
	{
		for (int j = rows; j > i; j--)
		{
			cout << " ";
		}
		for (int k = 1; k <= i; k++)
		{
			cout << k;
		}
		for (int l = i - 1; l >= 1; l--)
		{
			cout << l;
		}
		cout << "\n";
	}
}
C++ Program to Print Triangle of Mirrored Numbers Pattern

This C++ pattern example prints the triangle pattern of mirrored numbers using a while loop.

#include<iostream>
using namespace std;

int main()
{
	int rows, i, j, k, l;
	
	cout << "Enter Traingle Mirrored Numbers Rows = ";
	cin >> rows;

	cout << "Printing Traingle of Mirrored Numbers Pattern\n";
	i = 1;

	while (i <= rows)
	{
		j = rows;
		while (j > i)
		{
			cout << " ";
			j--;
		}

		k = 1;
		while (k <= i)
		{
			cout << k;
			k++;
		}

		l = i - 1;
		while (l >= 1)
		{
			cout << l;
			l--;
		}

		cout << "\n";
		i++;
	}
}
Enter Traingle Mirrored Numbers Rows = 9
Printing Traingle of Mirrored Numbers Pattern
        1
       121
      12321
     1234321
    123454321
   12345654321
  1234567654321
 123456787654321
12345678987654321

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.