- 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 180° Rotation of Simple Pyramid - Upside-Down Pyramid
Print 180° Rotation of Simple Pyramid
This pattern rotates the simple pyramid by 180°, producing a half pyramid aligned to the right. The top row contains one star after several spaces, and each subsequent row has one more star and one less space. The resulting pattern looks like this:
*
**
***
****
*****
#include <stdio.h>
int main() {
int rows;
printf("Enter number of rows: ");
scanf("%d", &rows);
for (int i = 1; i <= rows; i++) {
// Print leading spaces
for (int j = 1; j <= rows - i; j++) {
printf(" ");
}
// Print stars that align to the right
for (int j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
Enter number of rows: 5
*
**
***
****
*****
In each row the program prints fewer spaces and more stars as it progresses downward. The number of spaces printed is rows - i, which moves the first star further left for the top row and aligns the pattern to the right.
Comments
Loading comments...