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.

Sai Kishore Randhi, author
About the author

Sai Kishore Randhi

Embedded systems, VLSI, and chip design

Sai Kishore writes about embedded systems, VLSI, chip design, and the programming concepts behind modern hardware.

View LinkedIn profile ↗