C Program – Print Given Triangle - Right-Angled Star Pattern

Print Given Triangle

This pattern prints a left-aligned right-angled triangle using stars. The first row contains one star, the second row two stars, and so on up to the number of rows specified by the user. The pattern can be visualized as:

*
**
***
****
#include <stdio.h>
int main() {
    int rows;
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    for (int i = 1; i <= rows; i++) {
        for (int j = 1; j <= i; j++) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}
Enter number of rows: 4
*
**
***
****
        

The outer loop controls how many rows the triangle has, while the inner loop prints a number of stars equal to the current row number. After each row, a newline is printed to move to the next line.


Comments

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...