C Program to Print Hourglass Pattern Last Updated : 13 Dec, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report The Hourglass Pattern is a symmetrical pattern similar to an hourglass shape. It can be visualized as an inverted full pyramid placed on a regular full pyramid. In this article, we will learn how to print the Hourglass Pattern using a C program. Program to Print Hourglass Pattern in C Star Pattern #include <stdio.h> int main() { int n = 5; // Outer loop to iterate through each row for (int i = 0; i < 2 * n - 1; i++) { // Determine the row level relative to the center int l = (i < n) ? i : 2 * n - 2 - i; // Print leading spaces for (int j = 0; j < l; j++) { printf(" "); } // Print stars in the current row for (int k = 0; k < 2 * (n - l) - 1; 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 = 0; i < 2 * n - 1; i++) { // Determine the row level relative to the center int l = (i < n) ? i : 2 * n - 2 - i; // Print leading spaces for (int j = 0; j < l; j++) { printf(" "); } // Print numbers in the current row for (int k = 0; k < 2 * (n - l) - 1; k++) { printf("%d ", k + 1); } printf("\n"); } return 0; } Alphabet Pattern #include <stdio.h> int main() { int n = 5; // Outer loop to iterate through each row for (int i = 0; i < 2 * n - 1; i++) { // Determine the row level relative to the center int l = (i < n) ? i : 2 * n - 2 - i; // Print leading spaces for (int j = 0; j < l; j++) { printf(" "); } // Print alphabets in the current row for (int k = 0; k < 2 * (n - l) - 1; k++) { printf("%c ", k + 'A'); } printf("\n"); } return 0; } Output* * * * * * * * * | 1 2 3 4 5 6 7 8 9 | A B C D E F G H I * * * * * * * | 1 2 3 4 5 6 7 | A B C D E F G * * * * * | 1 2 3 4 5 | A B C D E * * * | 1 2 3 | A B C * | 1 | A * * * | 1 2 3 | A B C * * * * * | 1 2 3 4 5 | A B C D E * * * * * * * | 1 2 3 4 5 6 7 | A B C D E F G* * * * * * * * * | 1 2 3 4 5 6 7 8 9 | A B C D E F G H IExplanation:The outer loop runs for 2 * n - 1 iterations for printing each row of the pattern.For rows i < n, it processes the top half (inverted pyramid).For rows i >= n, it processes the bottom half (regular pyramid).The l variable determines the relative position of the current row from the top or bottom center:Top half: l = i.Bottom half: l = 2 * n - 2 - i.The first inner loop prints the number of leading spaces.The second inner loop prints the stars (or numbers/alphabet). Comment More infoAdvertise with us Next Article C Program to Print Hourglass Pattern A abhishekcpp Follow Improve Article Tags : C Programs C Language C Examples Similar Reads C Program to Print Hollow Hourglass Pattern The Hollow Hourglass Pattern is a symmetrical pattern that resembles an hourglass but with hollow spaces inside and only edges having characters. In this article, we will learn how to print the Hollow Hourglass Pattern using a C program. Program to Print Hollow Hourglass Pattern in CStar Pattern#inc 4 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 name pattern The printing of patterns is the most common and interesting problem. This C program prompts users to input their names and transform each letter of the name into a visually appealing big star pattern. For Example, Input: NAME Output: * * **** * * ****** ** * * * ** ** * * * * ****** * ** * **** * ** 5 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 C Program To Print Diamond Pattern The Diamond Pattern is a symmetrical shape where the number of characters increases up to the centre and then decreases forming a diamond-like structure. It can be visualized as a full pyramid and an inverted full pyramid joined by their bases. In this article, we will learn how to print the Diamond 4 min read Like