Mirror Right Triangle Star Pattern in C Language with Free Codes

Mirror Right Triangle Pattern

Mirror Right Triangle Pattern resemble a Right-Angled Triangle With the stars aligned to the right side of each row. However, unlike regular right triangle patterns where stars are aligned to the left, mirror right triangle patterns have stars aligned to the right. Each row has an increasing number of stars as it moves downwards, forming a triangular shape.

Output

Enter the number of rows: 5
    *
   **
  ***
 ****
*****
Free Hand-Written Notes

Codes – Mirror Right Triangle Pattern

#include <stdio.h>

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

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

    for (i = 1; i <= rows; i++) {
        // Print spaces
        for (j = 1; j <= rows - i; j++) {
            printf(" ");
        }
        // Print stars
        for (j = 1; j <= i; j++) {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

Codes Explanation

  1. The Codes Shows the Prompts to the user where user can enter the number of rows for the mirror right triangle.
  2. It iterates through each row using a for loop.
  3. Within each row, it prints spaces using another nested for loop to align the stars to the right. Then it prints stars using another nested for loop.
  4. The number of stars in each row increases with the row number.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top