C Program For Printing Right Half Pyramid Pattern
Last Updated :
15 Dec, 2024
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:
C
#include <stdio.h>
int main() {
int n = 5;
// Outer loop for printing rows
for (int i = 0; i < n; i++) {
// Inner loop for printing * in each rows
for (int j = 0; j <= i; j++)
printf("* ");
printf("\n");
}
return 0;
}
Output*
* *
* * *
* * * *
* * * * *
Explanation: Here, n is the number of rows to be printed.
- Outer loop print rows. It runs n times (0 to n-1) creating a new row in each iteration.
- Inner loop prints the star in each row. It runs from j = 0 up to the current value of i. This means:
- When i is 0, the inner loop runs once printing one star.
- When i is 1, the inner loop runs twice printing two star.
- And so on…
- The inner loop’s dependency on the outer loop’s variable (j <= i) is what creates the increasing number of stars per row, forming the triangle.
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.
Other Right Half Pyramid Pattern
Following are some of the variations of right half pyramid pattern:
Right Half Pyramid of a Number
The pattern consists of rows where each row contains the same number repeated.
C
#include <stdio.h>
int main() {
int n = 5;
// Outer loop for printing rows
for (int i = 0; i < n; i++) {
// Inner loop for printing 2 in each rows
for (int j = 0; j <= i; j++)
printf("2 ");
printf("\n");
}
return 0;
}
Output2
2 2
2 2 2
2 2 2 2
2 2 2 2 2
Right Half Pyramid of Row Numbers
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.
C
#include <stdio.h>
int main() {
int n = 5;
int i = 0;
// Outer loop for printing rows
while (i < n) {
int j = 0;
// Inner loop for printing numbers in each row
while (j <= i) {
printf("%d ", i + 1);
j++;
}
printf("\n");
i++;
}
return 0;
}
Output1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Right Half Pyramid of Consecutive Numbers in Each Row
Each row begins with 1 and increments by one for each consecutive number in that row.
C
#include <stdio.h>
int main() {
int n = 5;
// Outer loop for printing rows
for (int i = 0; i < n; i++) {
// Inner loop for printing numbers in each rows
for (int j = 0; j <= i; j++)
printf("%d ", j + 1);
printf("\n");
}
return 0;
}
Output1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Right Half Pyramid of Continious Numbers
This right half pyramid is made up of consecutive numbers starting from 1 and keeps incrementing till the end of the pattern is reached.
C
#include <stdio.h>
int main() {
int n = 5;
int c = 1;
// Outer loop for printing rows
for (int i = 0; i < n; i++) {
// Inner loop for printing numbers in each rows
for (int j = 0; j <= i; j++)
printf("%d ", c++);
printf("\n");
}
return 0;
}
Output1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
All these pyramids patterns can also be created using alphabets.
Right Half Pyramid of 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.
C
#include <stdio.h>
int main() {
int n = 5;
// Outer loop for printing rows
for (int i = 0; i < n; i++) {
// Inner loop for printing alphabet in each rows
for (int j = 0; j <= i; j++)
printf("%c ", i + 'A');
printf("\n");
}
return 0;
}
OutputA
B B
C C C
D D D D
E E E E E
Right Half Pyramid of Consecutive Numbers in Each Row
This pattern is also the most common alphabetical right half pyramid pattern. The do while loop is being used here for demonstration.
C
#include <stdio.h>
int main() {
int n = 5;
int i = 0;
// Outer loop for printing rows
do {
int j = 0;
// Inner loop for printing characters in each row
do {
printf("%c ", j + 'A');
j++;
} while (j <= i);
printf("\n");
i++;
} while (i < n);
return 0;
}
OutputA
A B
A B C
A B C D
A B C D E
Similar Reads
Pattern Programs in C
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 f
15+ min read
C Program For Printing Right Half Pyramid Pattern
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
5 min read
C Program to Print Pyramid Pattern
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 PatternRight half pyramid pattern looks l
13 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 Numb
6 min read
C Program to Print Continuous Character Pattern
Here, we will see how to print continuous character patterns using a C program. Below are the examples: Input: rows = 5Output: A B C D E F G H I J K L M N O Input: rows = 3Output: A B C D E F There are 2 ways to print continuous character patterns in C: Using for loop.Using while loop. Let's discuss
5 min read
C Program To Print Character Pyramid Pattern
Pyramid patterns is a classic logical programming exercise where a triangular looking pattern is printed by treating the output screen as a matrix and printing a given character. In this article, we will explore how to print various alphabet pyramid patterns using C program. Half Pyramid PatternHalf
4 min read
C Program to Print Right Half Pyramid Pattern
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 hypoten
2 min read
C Program To Print Hollow Pyramid Patterns
The Hollow Pyramid patterns are the variation of pyramid patterns where only the outer edges are filled with characters but the interior is left empty. In this article, we will learn how to print different hollow pyramid patterns. There can be 5 hollow pyramid patterns corresponding to each of the n
12 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 Pattern[GFGTABS] Star Cr
3 min read
Programs to print Interesting Patterns
Program to print the following pattern: Examples : Input : 5Output:* * * * * * * * * ** * * * * * * ** * * * * ** * * ** ** ** * * ** * * * * ** * * * * * * ** * * * * * * * * *This program is divided into four parts. [GFGTABS] C++ // C++ program to print // the given pattern #include<iostream
15+ min read