// Mon, Jan 19th, 2026

search notifications

Recursive Minds

Learn. Share. Recurse.

DATA_STRUCTURES_AND_ALGORITHMS

Print right angle triangle number pattern

📅 November 3, 2022 ✏️ Amit Kumar 💬 0 Comments ⏱️ 1 min read

In this article, we will learn about printing right-angle triangle star pattern

Input:  n = 5

Output:

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

Right Angle Number Pattern-1:

Java Code:

class Solution {

    void printTriangle(int n) {
        // i is used here for rows
        for(int i=1; i<=n; i++){
            // j is used for columns
            for(int j=1; j<=i; j++){
                System.out.print(j + " ");
            } 
            System.out.println();
        }
    }
}

 

C++ Code:

#include <iostream> 
using namespace std; 
// Driver code 
int main() { 
    int n = 5; 
    // ith row has i elements 
    for(int i = 1; i <= n; i++) { 
        for(int j = 1; j <= i; j++) 
            cout <<j + " "; 
        cout << endl; 
     } 
     return 0; 
}

 

Python Code:

x = int(input("Enter row number=\n")) 
for i in range(x): 
    for j in range(i+1): 
        print(j+1,end='') 
    print("")

 

Time Complexity:  O(n*n)

Space Complexity: O(1)

To Practice this Question on GFG

Click here

Other Questions on patterns:

Program to print square pattern in java, c++ and python

Program to print right angle triangle start pattern in Java, C++ and Python

Program to print right angle triangle number pattern-2 in JAVA, C++ and Python

← Previous Print right angle triangle star pattern Next → Print right angle triangle number pattern
Leave a comment