VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-print-pyramid-pattern/

⇱ C Program to Print Pyramid Pattern - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program to Print Pyramid Pattern

Last Updated : 15 Dec, 2024

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 Pattern

Right half pyramid pattern looks like a right-angle triangle in which the hypotenuse is towards the right i.e. all the characters are aligned to the right.


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

Left Half Pyramid Pattern

Right half pyramid pattern looks like a right-angle triangle with all the characters are aligned to the left resulting in the hypotenuse facing towards the left.


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

Full Pyramid Pattern

A full pyramid pattern is a pattern of star, numbers or alphabets that looks like an equilateral triangle.


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

Inverted Full Pyramid Pattern

Inverted full pyramid pattern is triangular pattern obtained by rotating the full pyramid pattern by 180°.


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

Diamond Pattern

The Diamond Pattern is triangular pattern that can be obtained by joining the full pyramid and inverted full pyramid pattern by their bases.


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

Hourglass Pattern

The Diamond Pattern is triangular pattern that can be obtained by joining the full pyramid and inverted full pyramid pattern by 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

Other Types of Pyramid Patterns in C

There can be a lot of variations of pyramid patterns that can be obtained by sight change in the pattern. Following are some common ones:

Comment