Beginner

Print Inverted Pyramid

Print inverted star pyramid

An inverted pyramid starts with the maximum stars at the top and decreases.

Program Code

inverted_pyramid.c
C
1#include <stdio.h>
2
3int main() {
4 int rows;
5
6 printf("Enter number of rows: ");
7 scanf("%d", &rows);
8
9 for (int i = rows; i >= 1; i--) {
10 // Print spaces
11 for (int j = 1; j <= rows - i; j++) {
12 printf(" ");
13 }
14 // Print stars
15 for (int k = 1; k <= 2 * i - 1; k++) {
16 printf("*");
17 }
18 printf("\n");
19 }
20
21 return 0;
22}
Output

Enter number of rows: 5

*********

*******

*****

***

*

Want to Learn More?

Explore our comprehensive tutorials for in-depth explanations of C programming concepts.

Browse Tutorials
Back to All Examples