Right Triangle Star Pattern in C Language with Free Codes

Right Triangle Pattern

A Right Triangle Star Pattern comprises rows where each row has an increasing number of stars which form a triangle shape which is lean towards the right side. The star are lie at the left side of each row, with subsequent rows having more stars than the preceding ones.

Output

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

Codes – Right Triangle Pattern

#include <stdio.h>

int main() {
    int rows;

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

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

    return 0;
}

Codes Explanation

  1. Here first the program prompts for the user to enter the number of rows for the right triangle.
  2. Then it will iterates through each row using a for loop.
  3. After iterate the it will within each row, it prints stars (*) using another nested for loop.
  4. The number of stars in each row increases with the row number.
  5. Finally, it moves to the next line to start the next row.

Leave a Comment

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

Scroll to Top