VOOZH about

URL: https://www.geeksforgeeks.org/c/pattern-programs-in-c/

⇱ Pattern Programs in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Pattern Programs in C

Last Updated : 4 Apr, 2026

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 following example programs for printing patterns in the C programming language.

👁 c_program_patterns

If you want to deep dive into loops and how they are applied in different scenarios, the C Programming Course Online with Data Structures provides extensive exercises and examples.

1. Right Half Pyramid Pattern

The right-half pyramid is nothing but a right-angle triangle whose hypotenuse is in the right direction. We can print the right half pyramid pattern using numbers, alphabets, or any other character like a star (*).

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

2. Left Half Pyramid Pattern

The Left Half Pyramid looks like a right-angled triangle with its hypotenuse facing the left. We can also print this pattern using a character, alphabets, or numbers.


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

3. Full Pyramid Pattern

The Full Pyramid pattern looks similar to the Equilateral triangle. We can see this as the combination of the Left Half and Right Half pyramids patterns. The following example demonstrates how to print this pattern using alphabets, numbers, or a star (*).


Output

 * | 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 I

4. Inverted Right Half Pyramid Pattern

This pattern is the 180° flipped version of the Right Half Pyramid Pattern we discussed earlier.


Output

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

5. Inverted Left Half Pyramid Pattern

This pattern is the 180° flipped version of the left half pyramid pattern we discussed earlier.


Output

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

6. Inverted Full Pyramid Pattern

It is a 180° flipped version of the Full Pyramid Pattern we discussed earlier. We can see this as the combination of the Inverted Left Half and Inverted Right Half Pyramid Pattern we discussed earlier.


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

7. Rhombus Pattern

The Rhombus pattern is similar to the square pattern, just that we have to add spaces before each line and their count decreases progressively with rows.


Output

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

8. Diamond Pattern

The Diamond Pattern is obtained by joining the Full Pyramid and Inverted Full Pyramid Pattern by their bases. We can also print this pattern using any character.


Output

 * | 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 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

9. Hourglass Pattern

Hourglass Pattern is a combination of the inverted full pyramid and full pyramid patterns but in the opposite sense to that of diamond pattern. Here we join them using their tip.


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 I

10. Hollow Square Pattern

The Hollow Square Pattern is a square with only the boundary lines. The space inside should be empty in this pattern.


Output

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

11. Hollow Full Pyramid Pattern

In the Hollow Pyramid pattern, we only have to print the boundary of the full pyramid.


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

12. Hollow Inverted Full Pyramid Pattern

In this pattern, we print the inverted full pyramid with only boundary elements and remove the inside elements to make it hollow.


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

13. Hollow Diamond Pattern

This pattern is also similar to the Diamond Pattern but without the inner elements such that it appears hollow inside.


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

14. Hollow Hourglass Pattern

The hollow hourglass is the pattern in which only the boundary of the hourglass pattern is visible.


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

15. Floyd's Triangle

In Floyd's Triangle pattern, instead of starting the sequence of the numbers from 1 in each row, we print consecutive natural numbers. We can also print this pattern for alphabet sequence.


Output

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

16. Pascal's Triangle

A Pascal's Triangle is a triangular array of binomial coefficients where the nth row contains the binomial coefficients nC0, nC1, nC2, ……. nCn. The following example demonstrates one of the methods using which we can print Pascal's Triangle Pattern.


Output
 1 
 1 1 
 1 2 1 
 1 3 3 1 
1 4 6 4 1 
Comment
Article Tags: