- 1C Program - Print Simple Pyramid Pattern
- 2C Program - Print Given Triangle
- 3C Program - Print 180° Rotation of Simple Pyramid
- 4C Program - Print Inverted Pyramid
- 5C Program - Print Number Pattern
- 6C Character Pattern Program
- 7C Hollow Star Pyramid Pattern
- 8C Floyd's Triangle Program
- 9C Pascal's Triangle Program
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.
⬅ Previous TopicC Program - Print 180° Rotation of Simple Pyramid
Next Topic ⮕C Program - Print Number Pattern
Next Topic ⮕C Program - Print Number Pattern
Comments
Loading comments...