C program to print reversed right triangle pattern

In this program, we are going to print reversed right triangle pattern in c. This program is similar to reversed right hollow triangle pattern program.
The pattern shape looks as shown below:

Only difference between right hollow triangle and reversed right hollow triangle is that the latter has blank spaces added in middle of shape.


To write program, knowledge of concepts like data types, variables, for loop, input output functions is necessary.


Looking at shape, it is visible that first row contains 5 star character, 2nd row contains 4 star character and next row contains one star character lesser than previous count. So here pattern is printed in decremented no. of times.

Here two for loops are used. First is parent for loop for iterating through rows and second is nested for loop used for iterating through columns.
Parent for loop iterates 0 to rows times and contains another for loop.
Nested for loop iterates I (dynamic value/can change) to rows times. This loop contains printf statement to print star pattern.

For more information please refer program execution and execution table.



Program explanation:

On line 1 and 2 is header files which includes predefined function definition of functions used in program like input output function etc.
Line 3 is main function which is program execution start point.

Line 5 declares loop counter variables like I,j and variable rows is used to accept user input which is later used to set limit in evaluate condition.
Line 6 and 7 are printf and scanf statement respectively which prints message to enter no. of rows to user and then scanf statement reads the user input.

Line 8 and 9 are for loops used in program.

  • Parent for loop is used for iterating through rows and its loop control variable is initialized to 0 (i=0). This loop iterates from 0 to rows times when evaluate condition specified(i<=rows) becomes true. And post fix increment(i++) is done after each successful iteration.
  • Nested for loop is used for iterating through columns and its loop control variable is initialized to I (j=i). this loop iterates through columns from I to rows times for every row when evaluate condition is successful(j<=rows). Post fix increment(j++) is done after each successful iteration.

Line 11 to 13 is body of nested for loop which contains printf statement for adding star pattern. This statement gets executed when evaluate condition in nested for loop is satisfied.

After closing nested for loop, printf statement to add new line to output is present immediate after nested for loop.
Line 17 is last statement in program which is return 0 statement to indicate successful completion of program.

Leave a Reply

%d bloggers like this: