Open In App

C Program to Print 180 Degree Rotation of Inverted Right Half Pyramid

Last Updated : 30 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The 180° rotation of a simple half left pyramid pattern leads to the pattern whose base is aligned with the bottom and characters are aligned to the left and increase in count while going down. In this article, we will learn how to print the 180° Rotated Half Left Pyramid using a C program.

180-rotated-inverted-right-half-pyramid

The below program implements this pattern using different characters:

Star Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // Outer loop to iterate through each row
    for (int i = 1; i <= n; i++) {
      
        // Print leading spaces
        for (int j = 1; j <= n - i; j++)
            printf("  ");

        // Print stars for the current row
        for (int k = 1; k <= i; k++)
            printf("* ");
        printf("\n");
    }

    return 0;
}
Number Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // Outer loop to iterate through each row
    for (int i = 1; i <= n; i++) {
      
        // Print leading spaces
        for (int j = 1; j <= n - i; j++)
            printf("  ");

        // Print stars for the current row
        for (int k = 1; k <= i; k++)
            printf("%d ", k);
        printf("\n");
    }

    return 0;
}
Alphabet Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // Outer loop to iterate through each row
    for (int i = 1; i <= n; i++) {
      
        // Print leading spaces
        for (int j = 1; j <= n - i; j++)
            printf("  ");

        // Print stars for the current row
        for (int k = 1; k <= i; k++)
            printf("%c ", k - 1 + 'A');
        printf("\n");
    }

    return 0;
}



Output

        *    |            1    |            A
* * | 1 2 | A B
* * * | 1 2 3 | A B C
* * * * | 1 2 3 4 | A B C D
* * * * * | 1 2 3 4 5 | A B C D E

Explanation:

  • The outer loop runs from i = 1 to i = n, printing the rows of the pyramid.
  • For the current row i, the number of spaces is n - i, where n is the total number of rows. These are printed by first inner loop.
  • The number of stars in a row corresponds to the current row number i. It is printed by second inner loop.

Next Article

Similar Reads