Program to Print Right Half Pyramid Pattern (Star Pattern) Last Updated : 29 Jan, 2024 Comments Improve Suggest changes Like Article Like Report Given an integer N, print N rows of right half pyramid pattern. In right half pattern of N rows, the first row has 1 star, second row has 2 stars and so on till the Nth row which has N stars. All the stars are left aligned. Examples: Input: 3Output: ****** Input: 5Output: *************** Approach: The problem can be solved using two nested loops. The outer loop will run for the rows and the inner loop will print the stars. Step-by-step approach: Run an outer loop from i = 1 to the number of rows.Run an inner loop from j = 1 to i.Print an asterisk in each iteration of the inner loop.Print a newline character ("\n") to move to the next row.After N iterations, we will have the right half pyramid pattern. Below is the implementation of the above approach: C++ #include <iostream> using namespace std; int main() { // Number of rows int N = 5; // Outer loop runs N times, once for each row for (int i = 1; i <= N; i++) { // Inner loop prints 'i' stars for (int j = 1; j <= i; j++) { cout << "*"; } // Move to the next line cout << "\n"; } return 0; } Java import java.util.Scanner; public class Main { public static void main(String[] args) { // Number of rows int N = 5; // Outer loop runs N times, once for each row for (int i = 1; i <= N; i++) { // Inner loop prints 'i' stars for (int j = 1; j <= i; j++) { System.out.print("*"); } // Move to the next line System.out.println(); } } } Python3 # Number of rows N = 5 # Outer loop runs N times, once for each row for i in range(1, N + 1): # Inner loop prints 'i' stars for j in range(1, i + 1): print("*", end="") # Move to the next line print() C# using System; class Program { static void Main() { // Number of rows int N = 5; // Outer loop runs N times, once for each row for (int i = 1; i <= N; i++) { // Inner loop prints 'i' stars for (int j = 1; j <= i; j++) { Console.Write("*"); } // Move to the next line Console.WriteLine(); } } } JavaScript // Number of rows let N = 5; // Outer loop runs N times, once for each row for (let i = 1; i <= N; i++) { // Inner loop prints 'i' stars for (let j = 1; j <= i; j++) { process.stdout.write("*"); } // Move to the next line console.log(); } Output* ** *** **** *****Time Complexity: O(N2), where N is the number of rows in the pattern.Auxiliary Space: O(1) Comment More infoAdvertise with us M mrityuanjay8vae Follow Improve Article Tags : DSA pattern-printing Scala-Arrays Explore DSA FundamentalsLogic Building Problems 2 min read Analysis of Algorithms 1 min read Data StructuresArray Data Structure 3 min read String in Data Structure 2 min read Hashing in Data Structure 2 min read Linked List Data Structure 2 min read Stack Data Structure 2 min read Queue Data Structure 2 min read Tree Data Structure 2 min read Graph Data Structure 3 min read Trie Data Structure 15+ min read AlgorithmsSearching Algorithms 2 min read Sorting Algorithms 3 min read Introduction to Recursion 14 min read Greedy Algorithms 3 min read Graph Algorithms 3 min read Dynamic Programming or DP 3 min read Bitwise Algorithms 4 min read AdvancedSegment Tree 2 min read Binary Indexed Tree or Fenwick Tree 15 min read Square Root (Sqrt) Decomposition Algorithm 15+ min read Binary Lifting 15+ min read Geometry 2 min read Interview PreparationInterview Corner 3 min read GfG160 3 min read Practice ProblemGeeksforGeeks Practice - Leading Online Coding Platform 6 min read Problem of The Day - Develop the Habit of Coding 5 min read Like