C Program to Print to Mirrored Right Triangle Star Pattern

Here is a C program to print a mirrored right angles triangle pattern of star character of n rows using for loop. For a mirrored right triangle star pattern of 7 rows. Program's output should be:


C program mirrored right triangle pattern

Required Knowledge

Algorithm to print mirrired right triangle star pattern using loop C program to print mirrored right triangle star pattern is similar to the right triangle star pattern program. Once you understand how to print right triangle pattern then printing it's mirrored pattern will be an easy task.
  • Take the number of rows(N) of mirrored right triangle as input from user using scanf function.
  • In any row, the sum of spaces and stars are equal to N. Number of stars increases by one and number of spaces before stars decreases by 1 in consecutive rows.
  • In any row R, we will first print N-R-1 space characters then R+1 star characters.

Here is the matrix representation of the inverted triangle star pattern. The row numbers are represented by i whereas column numbers are represented by j.

C program mirrored right triangle pattern

C program to print mirrored right triangle star pattern

#include <stdio.h>

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

    printf("Enter the number of rows\n");
    scanf("%d", &rows);

    for(i = 0; i < rows; i++){
        /* for j th row, first print rows-r spaces then stars */
        for(j = 0; j < rows; j++){
            if(j < rows-i-1){
                printf(" ");
            } else {
                printf("*");
            }
        }
        /* move to next row */
        printf("\n");
    }
    return 0;
}
Output
Enter the number of rows
6
     *
    **
   ***
  ****
 *****
******

Here is the C program to print inverted right triangle star pattern using one for loop
#include
 
int main(){
    char *str="*******************";
    int i,j, rows;
    
    printf("Enter the number of rows\n");
    scanf("%d", &rows); 
    
    for(i = 0; i < rows; i++){
       printf("%*.*s\n", rows, i+1, str);
    }
    
    return 0;
}
Output
Enter the number of rows
5
    *
   **
  ***
 ****
*****

Related Topics
C program inverted right triangle pattern
C program reversed right triangle star pattern
C program hollow pyramid star pattern
C program diamond star pattern
C program pyramid star pattern
C program hollow square star pattern
C program rhombus star pattern
C program reversed pyramid star pattern
C program binary triangle pattern
List of all C pattern programs