Open In App

C Program To Print Inverted Hollow Pyramid Patterns

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

In C, hollow inverted pyramids are pyramid patterns that are flipped 180° vertically with the characters present only at the edge while the inside remains empty. In this article, we will learn how to print different hollow inverted pyramid patterns using C programs.

There are three common inverted hollow pyramid patterns:

Inverted Hollow Right Half Pyramid

The Inverted Hollow Right Half Pyramid Pattern is a triangular pattern where the largest row is at the top and the rows decrease in size as we move downward.

Star Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // Loop for printing each row
    for (int i = 0; i < n; i++) {
      
      	// Inner loop for prinitng stars * and whitespaces
        for (int j = 0; j < n - i; j++) {
            if (j == 0 || j == n - i - 1 || i == 0)
                printf("* ");
            else
                printf("  ");
        }
        printf("\n");
    }

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

int main() {
    int n = 5;

    // Loop for printing each row
    for (int i = 0; i < n; i++) {
      
      	// Inner loop for prinitng numbers and whitespaces
        for (int j = 0; j < n - i; j++) {
            if (j == 0 || j == n - i - 1 || i == 0)
                printf("%d ", j + 1);
            else
                printf("  ");
        }
        printf("\n");
    }

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

int main() {
    int n = 5;

    // Loop for printing each row
    for (int i = 0; i < n; i++) {
      
      	// Inner loop for prinitng alphabets and whitespaces
        for (int j = 0; j < n - i; j++) {
            if (j == 0 || j == n - i - 1 || i == 0)
                printf("%c ", j + 'A');
            else
                printf("  ");
        }
        printf("\n");
    }

    return 0;
}


Output

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

Inverted Hollow Left Half Pyramid

The Inverted Hollow Left Half Pyramid Pattern is similar to the inverted hollow right half pyramid, but the characters are aligned to the right. The largest row is at the top, and the rows decrease in size as we move downward.

Star Pattern
#include <stdio.h>

int main() {
    int n = 5; 
  
    // Loop to print each row
    for (int i = 0; i < n; i++) {
      
      	// Print leading spaces for alignment
        for (int j = 0; j < i; j++)
            printf("  ");
      
      	// Print star * and inner whitespaces
        for (int j = 0; j < n - i; j++) {
            if (j == 0 || j == n - i - 1 || i == 0)
                printf("* ");
            else
                printf("  ");
        }
        printf("\n");
    }

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

int main() {
    int n = 5; 
  
    // Loop to print each row
    for (int i = 0; i < n; i++) {
      
      	// Print leading spaces for alignment
        for (int j = 0; j < i; j++)
            printf("  ");
      
      	// Print star * and inner whitespaces
        for (int j = 0; j < n - i; j++) {
            if (j == 0 || j == n - i - 1 || i == 0)
                printf("%d ", j + 1);
            else
                printf("  ");
        }
        printf("\n");
    }

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

int main() {
    int n = 5; 
  
    // Loop to print each row
    for (int i = 0; i < n; i++) {
      
      	// Print leading spaces for alignment
        for (int j = 0; j < i; j++)
            printf("  ");
      
      	// Print star * and inner whitespaces
        for (int j = 0; j < n - i; j++) {
            if (j == 0 || j == n - i - 1 || i == 0)
                printf("%c ", j + 'A');
            else
                printf("  ");
        }
        printf("\n");
    }

    return 0;
}


Output

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

Inverted Hollow Full Pyramid

The Inverted Hollow Full Pyramid Pattern is a variation of the inverted full pyramid where only the outer edges are filled with characters, and the inside is left empty.

Star Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // First loop iterating through each row
    for (int i = 0; i < n; i++) {

        // First inner loop to print leading white space
        for (int j = 0; j < 2 * i + 1; j++)
            printf(" ");

        // Second inner loop to print star* and hollow white
        // space
        for (int k = 0; k < 2 * (n - i) - 1; k++) {
            if (k == 0 || k == 2 * (n - i) - 2 || i == 0)
                printf("* ");
            else
                printf("  ");
        }
        printf("\n");
    }
    
    return 0;
}
Number Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // First loop iterating through each row
    for (int i = 0; i < n; i++) {

        // First inner loop to print leading white space
        for (int j = 0; j < 2 * i + 1; j++)
            printf(" ");

        // Second inner loop to print number and hollow white
        // space
        for (int k = 0; k < 2 * (n - i) - 1; k++) {
            if (k == 0 || k == 2 * (n - i) - 2 || i == 0)
                printf("%d ", k + 1);
            else
                printf("  ");
        }
        printf("\n");
    }
    
    return 0;
}
Alphabet Pattern
#include <stdio.h>

int main() {
    int n = 5;

    // First loop iterating through each row
    for (int i = 0; i < n; i++) {

        // First inner loop to print leading white space
        for (int j = 0; j < 2 * i + 1; j++)
            printf(" ");

        // Second inner loop to print number and hollow white
        // space
        for (int k = 0; k < 2 * (n - i) - 1; k++) {
            if (k == 0 || k == 2 * (n - i) - 2 || i == 0)
                printf("%c ", k + 'A');
            else
                printf("  ");
        }
        printf("\n");
    }
    
    return 0;
}


Output

* * * * * * * * *   |   1 2 3 4 5 6 7 8 9   |   A B C D E F G H I
* * | 1 7 | A G
* * | 1 5 | A E
* * | 1 3 | A C
* | 1 | A

Next Article

Similar Reads