C program to print mirrored right triangle star pattern

  • Write a program in C to print mirrored right angled triangle star (*) pattern using for loop.
  • Write a C program to print a mirrored right angles triangle pattern of star (*) character of n rows.
For a mirrored right triangle star pattern of 5 rows. Program's output should be:
    *
   **
  ***
 ****
*****

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 space characters then R star characters.

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 = 1; i <= rows; i++){  
    /* for r th row, first print rows-r spaces then stars */
        for(j = 1; j <= rows; j++){
            if(j <= rows-i){
                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