C program to print reversed right hollow triangle pattern

In this program, we are going to print reversed right hollow triangle star pattern. This program is similar to reversed right triangle pattern.
Before proceeding with program, take a look at shape in which we are going to display pattern.

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

Pre-requisite:

to be able to write this program, basic knowledge of concepts like data types, variables, for loop, input output function, main function is necessary.

Approach:

As seen in shape of reversed right hollow triangle, we can conclude few points to be able to start applying our calculations. Here we have to find out first where star pattern is to be displayed and where blank space need to be displayed. In this shape, we have first row and first column of every row which has star pattern.

and forward slash shaped vertical row which joints horizontal and vertical sides.

So to print the forward slash shape, if we take a look at middle rows we can find that middle rows has only two star pattern on their row and last star pattern gets closer to first star pattern on particular row on every new iteration i.e. gap between these two gets reduced on every new iteration. So for that we can do one thing that is to rotate nested for loop through columns each time lesser than previous iteration and print star pattern on last column of row.

So for first parent loop iteration, nested for loop will rotate through 5 columns of row and print star pattern on first(1) and last column(5). On next iteration, nested for loop will rotate through 4 columns of row and print star pattern on first(1) and last column(4) and so on.

This program makes use of two for loops:
Parent for loop for rotating through columns and nested for loop for rotating through columns.

Program:

Output:

Leave a Reply

%d bloggers like this: