C Program to Print Right Triangle of Mirrored Numbers Pattern

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

#include <stdio.h>

int main()
{
	int rows;

	printf("Enter Right Traingle Mirrored Numbers Rows = ");
	scanf("%d", &rows);

	printf("Right Traingle of Mirrored Numbers\n");
	
	for (int i = 1; i <= rows; i++)			
	{
		for (int j = 1; j <= i; j++)		
		{
			printf("%d", j);
		}
		for (int k = i - 1; k >= 1; k--)	
		{
			printf("%d", k);
		}
		printf("\n");
	}
}
C Program to Print Right Triangle of Mirrored Numbers Pattern

This C program prints the right angled triangle pattern of mirrored numbers using a while loop.

#include <stdio.h>

int main()
{
	int i, j, k, rows;

	printf("Enter Right Traingle Mirrored Numbers Rows = ");
	scanf("%d", &rows);

	printf("Right Traingle of Mirrored Numbers\n");
	
	i = 1;
	while (i <= rows)
	{
		j = 1;
		while (j <= i)
		{
			printf("%d", j);
			j++;
		}

		k = i - 1;
		while (k >= 1)
		{
			printf("%d", k);
			k--;
		}
		printf("\n");
		i++;
	}
}
Enter Right Traingle Mirrored Numbers Rows = 10
Right Traingle of Mirrored Numbers
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
12345678910987654321

This C example uses the rMirroredNumbers function to print the right angled triangle of mirrored numbers pattern.

#include <stdio.h>

void rtMirroredNumbers(int rows);

int main()
{
	int rows;

	printf("Enter Right Traingle Mirrored Numbers Rows = ");
	scanf("%d", &rows);

	printf("Right Traingle of Mirrored Numbers\n");
	rtMirroredNumbers(rows);
}

void rtMirroredNumbers(int rows)
{
	for (int i = 1; i <= rows; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			printf("%d", j);
		}
		for (int k = i - 1; k >= 1; k--)
		{
			printf("%d", k);
		}
		printf("\n");
	}
}
Enter Right Traingle Mirrored Numbers Rows = 13
Right Traingle of Mirrored Numbers
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
12345678910987654321
123456789101110987654321
1234567891011121110987654321
12345678910111213121110987654321

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.