How to write a C Program to Print Mirrored Right Triangle Star Pattern with example?. And also show you how to print Mirrored Right Triangle Pattern with different symbols.
C Program to Print Mirrored Right Triangle Star Pattern
This C program allows the user to enter the maximum number of rows he/she want to print as a Mirrored Right Triangle. We are going to print the * symbols until it reaches the user-specified rows.
/* C Program to Print Mirrored Right Triangle Star Pattern */
#include <stdio.h>
int main()
{
int Rows, i, j;
printf("Please Enter the Number of Rows: ");
scanf("%d", &Rows);
printf("\nPrinting Mirrored Right Triangle Increasing Star Pattern \n");
for ( i = 1 ; i <= Rows; i++ )
{
for ( j = 1 ; j <= Rows; j++ )
{
if(j <= Rows-i)
{
printf(" ");
}
else
{
printf("*");
}
}
printf("\n");
}
return 0;
}

Let us see the Nested for loop in C language
Outer Loop – First Iteration
From the above C Programming image, you can observe that the value of i is 1 and Rows is 6 so, the condition (i <= 6) is True. So, it will enter into second for loop
Inner Loop – First Iteration: The j value is 1 and the condition (j <= 6) is True. So, it will start executing the statements inside the loop. It means the compiler will enter into the C If Statement. Here, we are checking whether j <= Rows-i (1 <= 5) . If this condition is true, then printf(” “) will be executed. Otherwise, printf(“*”) will execute.
It happens 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. For more star pattern examples, please refer to the C Star Pattern Programs article.
C Program to Print Mirrored Right Triangle Pattern
This program allows the user to enter the Symbol and number of rows he/she want to print. It means, instead of printing pre-defined stars, it allows the user to enter their own character.
#include <stdio.h>
int main()
{
int Rows, i, j;
char Ch;
printf("Please Enter any Symbol : ");
scanf("%c", &Ch);
printf("Please Enter the Number of Rows: ");
scanf("%d", &Rows);
printf("\nPrinting Mirrored Right Triangle Increasing Star Pattern \n");
for ( i = 1 ; i <= Rows; i++ )
{
for ( j = 1 ; j <= Rows; j++ )
{
if(j <= Rows-i)
{
printf(" ");
}
else
{
printf("%c", Ch);
}
}
printf("\n");
}
return 0;
}
Please Enter any Symbol : $
Please Enter the Number of Rows: 9
Printing Mirrored Right Triangle Increasing Star Pattern
$
$$
$$$
$$$$
$$$$$
$$$$$$
$$$$$$$
$$$$$$$$
$$$$$$$$$
C Program for Mirrored Right Triangle Star Pattern using While Loop
In this C program to return mirrored right triangle star pattern, we just replaced the For Loop with the While Loop. I suggest you refer C Programming While Loop article to understand the logic.
#include <stdio.h>
int main()
{
int Rows, i = 1, j;
char Ch;
printf("Please Enter any Symbol : ");
scanf("%c", &Ch);
printf("Please Enter the Number of Rows: ");
scanf("%d", &Rows);
printf("\nPrinting Mirrored Right Triangle Increasing Star Pattern\n");
while ( i <= Rows)
{
for ( j = 1 ; j <= Rows; j++ )
{
if(j <= Rows-i)
{
printf(" ");
}
else
{
printf("%c", Ch);
}
}
printf("\n");
i++;
}
return 0;
}
Please Enter any Symbol : *
Please Enter the Number of Rows: 11
Printing Mirrored Right Triangle Increasing Star Pattern
*
**
***
****
*****
******
*******
********
*********
**********
***********
Also Read
- C Program to Print Hollow Mirrored Right Triangle Star Pattern
- C Program to Print Reversed Mirrored Right Triangle
Comments are closed.