C Program – Print Inverted Pyramid - Upside Down Triangle

Print Inverted Pyramid

In this pattern, the largest row of stars appears at the top and each subsequent row contains two fewer stars, creating an upside-down pyramid. Leading spaces increase with each row to maintain centering.

#include <stdio.h>
int main() {
    int rows;
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    for (int i = rows; i >= 1; i--) {
        // Print leading spaces
        for (int j = 0; j < rows - i; j++) {
            printf(" ");
        }
        // Print stars for the current row
        for (int k = 1; k <= 2 * i - 1; k++) {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}
Enter number of rows: 4
*******
  *****
  ***
    *
        

The pattern is generated by starting with the maximum number of stars (2×rows−1) in the first row, then decreasing the number of stars by two each row. Leading spaces increase accordingly to center the inverted triangle.

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 ↗