In this article, we will learn about printing right-angle triangle star pattern
Input: n = 5
Output:
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Right Angle Number Pattern-2:
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(i + " ");
}
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 <<i + " ";
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(i+1,end='')
print("")
Time Complexity: O(n*n)
Space Complexity: O(1)
To Practice this Question on GFG
Other Questions on patterns:
Program to print square pattern in java, c++ and python
Program to print right angle triangle star pattern in Java, C++ and Python
Program to print right angle triangle number pattern-1 in Java, C++, and Python

