C Program to Print Inverted Right Triangle Number Pattern

How to write a C Program to Print Inverted Right Triangle Number Pattern with example?. Or, C Program to display Inverted Right Angled Triangle Number Pattern.

C Program to Print Inverted Right Triangle Number Pattern Example 1

This program allows the user to enter the maximum number of rows he/she want to print as an inverted right angled triangle. Next, the compiler will print the inverted right triangle of numbers from maximum value to minimum, until it reaches the user-specified rows.

/* C Program to Print Inverted Right Triangle Number Pattern */

#include <stdio.h>
 
int main() 
{
  	int rows, i, j;
	
  	printf("Please Enter the Number of Rows:  ");
  	scanf("%d", &rows);
	
  	for ( i = rows; i >= 1; i-- ) 
  	{
      	for ( j = 1 ; j <= i; j++ ) 
      	{
          	printf("%d", i);
      	}
      	printf("\n");
  	}
  	return 0;
}
C Program to Print Inverted Right Triangle Number Pattern 1

Let us see the Nested for loop

for ( i = rows; i >= 1; i-- ) 
{
      	for ( j = 1 ; j <= i; j++ ) 
      	{
          	printf(" %d", i);
      	}
      	printf("\n");
}

Outer Loop – First Iteration

From the above C Programming screenshot, you can observe that the value of i is 8, and the condition (i >= 1) is True. So, it will enter into second for loop

Inner Loop – First Iteration
The j value is 1 and the condition (1 <= 1) is True. So, it will start executing the statements inside the loop. The following statement will print 8 as Output

printf(" %d", i);

The following statement will increment j by1 using the Increment Operator

j++

It will happen until the condition inside the inner for loop fails. Next, iteration will start from the beginning until both the Inner Loop and Outer loop conditions fail.

Program to display Inverted Right Triangle Number Pattern Example 2

In this C program for inverted right triangle, we just replaced the For Loop with the While Loop. I suggest you refer While Loop article to understand the logic.

/* C Program to Print Inverted Right Triangle Number Pattern */

#include <stdio.h>
 
int main() 
{
  	int rows, i, j;
	
  	printf("Please Enter the Number of Rows:  ");
  	scanf("%d", &rows);
  
  	i = rows;
	
  	while ( i >= 1) 
  	{
  		j = 1 ;
      	while (  j <= i ) 
      	{
          	printf("%d", i);
          	j++;
      	}
      	i--;
      	printf("\n");
  	}
  	return 0;
}
Please Enter the Number of Rows:  9
999999999
88888888
7777777
666666
55555
4444
333
22
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.