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

💬 Please keep your comment relevant and respectful. Avoid spamming, offensive language, or posting promotional/backlink content.
All comments are subject to moderation before being published.


Loading comments...