![]() |
VOOZH | about |
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 how to print different right-half pyramid patterns using C program.
The patterns are printed by visualizing the output space as a matrix with rows and columns and then printing the characters or whitespace according to the shape we want. Let's take a look at an example for right-half pyramid pattern:
* * * * * * * * * * * * * * *
Explanation: Here, n is the number of rows to be printed.
Any shape that resembles the above pattern can be called a right half pyramid. Due to this, there can be different variations of this pattern based on the characters used to print it.
Note: We can use other loops too but using for loop is most suitable for this type of problems.
Following are some of the variations of right half pyramid pattern:
Table of Content
The pattern consists of rows where each row contains the same number repeated.
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
In this pattern, each row is made up of its own row number. In this program, we are using while loop instead of for loop.
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Each row begins with 1 and increments by one for each consecutive number in that row.
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
This right half pyramid is made up of consecutive numbers starting from 1 and keeps incrementing till the end of the pattern is reached.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
All these pyramids patterns can also be created using alphabets.
This pattern is the alphabet version of the right half pyramid with row numbers. 'A' is just added to the loop variable to align it with the ASCII values of uppercase alphabets.
A B B C C C D D D D E E E E E
This pattern is also the most common alphabetical right half pyramid pattern. The do while loop is being used here for demonstration.
A A B A B C A B C D A B C D E