C Program to Print Square of Right Decrement Numbers Pattern

Write a C program to print square of right decrement numbers pattern using for loop.

#include <stdio.h>

int main()
{
	int rows;

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

	printf("The Square of Right Decrement Numbers Pattern\n");

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

This C program prints the square pattern of right decremented numbers using a while loop.

#include <stdio.h>

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

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

	printf("The Square of Right Decrement Numbers Pattern\n");
	i = rows;

	while (i >= 1)
	{
		j = rows;
		while (j >= i)
		{
			printf("%d ", j);
			j--;
		}
		k = rows - i + 1;
		while (k < rows)
		{
			printf("%d ", i);
			k++;
		}
		printf("\n");
		i--;
	}
}
Enter Square Right Decrement Numbers Rows = 9
The Square of Right Decrement Numbers Pattern
9 9 9 9 9 9 9 9 9 
9 8 8 8 8 8 8 8 8 
9 8 7 7 7 7 7 7 7 
9 8 7 6 6 6 6 6 6 
9 8 7 6 5 5 5 5 5 
9 8 7 6 5 4 4 4 4 
9 8 7 6 5 4 3 3 3 
9 8 7 6 5 4 3 2 2 
9 8 7 6 5 4 3 2 1 

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.