C Program To Print Hollow Pyramid Patterns
Last Updated :
13 Dec, 2024
The Hollow Pyramid patterns are the variation of pyramid patterns where only the outer edges are filled with characters but the interior is left empty. In this article, we will learn how to print different hollow pyramid patterns.
There can be 5 hollow pyramid patterns corresponding to each of the normal pyramid pattern in C:
Hollow Right Half Pyramid
The hollow right half pyramid pattern looks like a right-angled triangle aligned to the left and with its hypotenuse towards right. It only contains the characters at its boundary and is left hollow inside.
Star Pattern
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print each row
for (int i = 1; i <= n; i++) {
// Inner loop to print the whitespace and stars
for (int j = 1; j <= i; j++) {
// Print '*' for first or last column, or last row
// print whitespaces for the rest
if (j == 1 || j == i || i == n)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Number Pattern
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print each row
for (int i = 1; i <= n; i++) {
// Inner loop to print the whitespace and numbers
for (int j = 1; j <= i; j++) {
// Print numbers for first or last column, or last row
// print whitespaces for the rest
if (j == 1 || j == i || i == n)
printf("%d ", j);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Alphabet Pattern
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print each row
for (int i = 1; i <= n; i++) {
// Inner loop to print the whitespace and alphabets
for (int j = 1; j <= i; j++) {
// Print alphabets for first or last column, or last row
// print whitespaces for the rest
if (j == 1 || j == i || i == n)
printf("%c ", j - 1 + 'A');
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
* | 1 | A
* * | 1 2 | A B
* * | 1 3 | A C
* * | 1 4 | A D
* * * * * | 1 2 3 4 5 | A B C D E
Hollow Left Half Pyramid
The hollow left half pyramid pattern also looks like a right-angled triangle but aligned to the right with its hypotenuse towards left and hollow from inside.
Star Pattern
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print each row
for (int i = 1; i <= n; i++) {
// Print leading white spaces
for (int j = 1; j <= n - i; j++)
printf(" ");
// Print '*' for first or last column, or last row
// print whitespaces for the rest
for (int k = 1; k <= i; k++) {
if (k == 1 || k == i || i == n)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Number Pattern
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print each row
for (int i = 1; i <= n; i++) {
// Print leading white spaces
for (int j = 1; j <= n - i; j++)
printf(" ");
// Print numbers for first or last column, or last row
// print whitespaces for the rest
for (int k = 1; k <= i; k++) {
if (k == 1 || k == i || i == n)
printf("%d ", k);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Alphabet Pattern
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print each row
for (int i = 1; i <= n; i++) {
// Print leading white spaces
for (int j = 1; j <= n - i; j++)
printf(" ");
// Print characters for first or last column, or last row
// print whitespaces for the rest
for (int k = 1; k <= i; k++) {
if (k == 1 || k == i || i == n)
printf("%c ", k - 1 + 'A');
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
* | 1 | A
* * | 1 2 | A B
* * | 1 3 | A C
* * | 1 4 | A D
* * * * * | 1 2 3 4 5 | A B C D E
Hollow Full Pyramid
The hollow full pyramid pattern looks like an equilateral triangle with the characters present at the edges, but the inside remains empty.
Star Pattern
#include <stdio.h>
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
// Print leading whitespaces
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int k = 1; k <= 2 * i - 1; k++) {
// Print '*' for first or last position in the row
// Print whitespace for the rest
if (k == 1 || k == 2 * i - 1 || i == n)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Number Pattern
#include <stdio.h>
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
// Print leading whitespaces
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int k = 1; k <= 2 * i - 1; k++) {
// Print number for first or last position in the row
// Print whitespace for the rest
if (k == 1 || k == 2 * i - 1 || i == n)
printf("%d ", k);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Alphabet Pattern
#include <stdio.h>
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
// Print leading whitespaces
for (int j = 1; j <= n - i; j++)
printf(" ");
for (int k = 1; k <= 2 * i - 1; k++) {
// Print alphabet for first or last position in the row
// Print whitespace for the rest
if (k == 1 || k == 2 * i - 1 || i == n)
printf("%c ", k - 1 + 'A');
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
* | 1 | A
* * | 1 3 | A C
* * | 1 5 | A E
* * | 1 7 | A G
* * * * * * * * * | 1 2 3 4 5 6 7 8 9 | A B C D E F G H I
Hollow Diamond Pattern
This pattern is also similar to the Diamond Pattern but without the inner elements such that it appears hollow inside.
Star Pattern
#include <stdio.h>
int main() {
int n = 5;
// First outer loop to print each row
for (int i = 0; i < 2 * n - 1; i++) {
// Assigning values to the level according to
// the row number
int l;
if (i < n) l = 2 * (n - i) - 1;
else l = 2 * (i - n + 1) + 1;
// First inner loop to print leading whitespaces
for (int j = 0; j < l; j++)
printf(" ");
// Second inner loop to print star * and inner
// whitespaces
for (int k = 0; k < 2 * n - l; k++) {
if (k == 0 || k == 2 * n - l - 1)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Number Pattern
#include <stdio.h>
int main() {
int n = 5;
// First outer loop to print each row
for (int i = 0; i < 2 * n - 1; i++) {
// Assigning values to the level according to
// the row number
int l;
if (i < n)
l = 2 * (n - i) - 1;
else
l = 2 * (i - n + 1) + 1;
// First inner loop to print leading whitespaces
for (int j = 0; j < l; j++)
printf(" ");
// Second inner loop to print star * and inner
// whitespaces
for (int k = 0; k < 2 * n - l; k++) {
if (k == 0 || k == 2 * n - l - 1)
printf("%d ", k + 1);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Alphabet Pattern
#include <stdio.h>
int main() {
int n = 5;
// First outer loop to print each row
for (int i = 0; i < 2 * n - 1; i++) {
// Assigning values to the level according to
// the row number
int l;
if (i < n)
l = 2 * (n - i) - 1;
else
l = 2 * (i - n + 1) + 1;
// First inner loop to print leading whitespaces
for (int j = 0; j < l; j++)
printf(" ");
// Second inner loop to print star * and inner
// whitespaces
for (int k = 0; k < 2 * n - l; k++) {
if (k == 0 || k == 2 * n - l - 1)
printf("%c ", k + 'A');
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output
* | 1 | A
* * | 1 3 | A C
* * | 1 5 | A E
* * | 1 7 | A G
* * | 1 9 | A I
* * | 1 7 | A G
* * | 1 5 | A E
* * | 1 3 | A C
* | 1 | A
Hollow Hourglass Pattern
The hollow hourglass is the pattern in which only the boundary of the hourglass pattern is visible.
Star Pattern
#include <stdio.h>
int main() {
int n = 5;
// First outer loop to iterate through each row
for (int i = 0; i < 2 * n - 1; i++) {
// Assigning level according to row number
int l;
if (i < n) l = 2 * i + 1;
else l = 2 * (2 * n - i) - 3;
// First inner loop to print leading whitespaces
for (int j = 0; j < l; j++)
printf(" ");
// Second inner loop to print star * and inner
// whitespaces
for (int k = 0; k < 2 * n - l; k++) {
if (k == 0 || k == 2 * n - l - 1 || i == 0
|| i == 2 * n - 2)
printf("* ");
else
printf(" ");
}
printf("\n");
}
return 0;
}
Number Pattern
#include <stdio.h>
int main() {
int n = 5;
// First outer loop to iterate through each row
for (int i = 0; i < 2 * n - 1; i++) {
// Assigning level according to row number
int l;
if (i < n)
l = 2 * i + 1;
else
l = 2 * (2 * n - i) - 3;
// First inner loop to print leading whitespaces
for (int j = 0; j < l; j++)
printf(" ");
// Second inner loop to print star * and inner
// whitespaces
for (int k = 0; k < 2 * n - l; k++) {
if (k == 0 || k == 2 * n - l - 1 || i == 0
|| i == 2 * n - 2)
printf("%d ", k + 1);
else
printf(" ");
}
printf("\n");
}
return 0;
}
Alphabet Pattern
#include <stdio.h>
int main() {
int n = 5;
// First outer loop to iterate through each row
for (int i = 0; i < 2 * n - 1; i++) {
// Assigning level according to row number
int l;
if (i < n)
l = 2 * i + 1;
else
l = 2 * (2 * n - i) - 3;
// First inner loop to print leading whitespaces
for (int j = 0; j < l; j++)
printf(" ");
// Second inner loop to print star * and inner
// whitespaces
for (int k = 0; k < 2 * n - l; k++) {
if (k == 0 || k == 2 * n - l - 1 || i == 0
|| i == 2 * n - 2)
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
* * | 1 3 | A C
* * | 1 5 | A E
* * | 1 7 | A G
* * * * * * * * * | 1 2 3 4 5 6 7 8 9 | A B C D E F G H I
Similar Reads
Pattern Programs in C
Printing patterns using C programs has always been an interesting problem domain. We can print different patterns like star patterns, pyramid patterns, Floyd's triangle, Pascal's triangle, etc. in C language. These problems require the knowledge of loops and if-else statements.We will discuss the fo
15+ min read
C Program For Printing Right Half Pyramid Pattern
A half-right pyramid consists of rows with sequential stars, numbers or characters arranged in a triangular shape. The first row has one character, the second row has two, and so on. The characters are aligned to the left making it similar to the right-angle triangle. In this article, we will learn
5 min read
C Program to Print Pyramid Pattern
In C, a pyramid pattern consists of numbers, stars, or alphabets arranged in a triangular shape. In this article, we will learn how to print different shapes of pyramid patterns using C program.Following are the 6 common pyramid patterns:Right Half Pyramid PatternRight half pyramid pattern looks lik
13 min read
C Program to Print Number Pattern
A number pattern involves printing numbers in a specific arrangement or shape, often in the form of a pyramid, triangle, or other geometric shapes. They are great for practicing loops and conditional statements. In this article, we will learn how to print different number patterns in C.Rhombus Numbe
6 min read
C Program to Print Continuous Character Pattern
Here, we will see how to print continuous character patterns using a C program. Below are the examples: Input: rows = 5Output: A B C D E F G H I J K L M N O Input: rows = 3Output: A B C D E F There are 2 ways to print continuous character patterns in C: Using for loop.Using while loop. Let's discuss
5 min read
C Program To Print Character Pyramid Pattern
Pyramid patterns is a classic logical programming exercise where a triangular looking pattern is printed by treating the output screen as a matrix and printing a given character. In this article, we will explore how to print various alphabet pyramid patterns using C program.Half Pyramid PatternHalf
4 min read
C Program to Print Right Half Pyramid Pattern
The Right Half Pyramid Pattern is a triangular pattern consists of rows where each row contains an increasing number of characters. The number of characters starts from 1 and increases by 1 in each subsequent row. Characters are aligned to the left, resembling a right-angle triangle with its hypoten
2 min read
C Program To Print Hollow Pyramid Patterns
The Hollow Pyramid patterns are the variation of pyramid patterns where only the outer edges are filled with characters but the interior is left empty. In this article, we will learn how to print different hollow pyramid patterns.There can be 5 hollow pyramid patterns corresponding to each of the no
12 min read
C Program to Print Cross or X Pattern
The Cross or X Pattern is a pattern where characters or stars are printed diagonally from top-left to bottom-right and from top-right to bottom-left, forming an "X" shape. In this article, we will learn how to print this pattern using a C program. Program to Print Cross or X PatternStar Cross#includ
3 min read
Programs to print Interesting Patterns
Program to print the following pattern: Examples : Input : 5Output:* * * * * * * * * ** * * * * * * ** * * * * ** * * ** ** ** * * ** * * * * ** * * * * * * ** * * * * * * * * *This program is divided into four parts.C++// C++ program to print // the given pattern #include<iostream> using name
15+ min read