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 hypotenuse in right direction.
In this article, we will learn how to print a right half pyramid pattern in C.

#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print all rows
for (int i = 0; i < n; i++) {
// Inner loop to print the * in each row
for (int j = 0; j <= i; j++)
printf("* ");
printf("\n");
}
}
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print all rows
for (int i = 0; i < n; i++) {
// Inner loop to print number in each row
for (int j = 0; j <= i; j++)
printf("%d ", j + 1);
printf("\n");
}
}
#include <stdio.h>
int main() {
int n = 5;
// Outer loop to print all rows
for (int i = 0; i < n; i++) {
// Inner loop to print alphabet in each row
for (int j = 0; j <= i; j++)
printf("%c ", j + 'A');
printf("\n");
}
}
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
Explanation:
- Outer loop iterates over the rows, from i = 0 to i = n - 1.
- Inner loop prints the stars (*) (or number/character) on each row. The number of stars printed increases as i increases. On row i, it prints i + 1 stars.