In this article, we will learn about printing right angle star pattern
Input: n = 5
Output:
* * * * * * * * * * * * * * *
Right Angle Star Pattern:
Java Code:
import java.io.*; // Java code to demonstrate right star triangle public class RecursiveMinds { // Function to demonstrate printing pattern public static void rightAngleTriangle(int n) { int i, j; // outer loop to handle number of rows // n in this case for (i = 0; i < n; i++) { // inner loop to handle number of columns // values changing according to outer loop for (j = 0; j <= i; j++) { // printing stars System.out.print("* "); } // end-line System.out.println(); } } // Driver Function public static void main(String args[]) { int n = 5; rightAngleTriangle(n); } }
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 << "* "; 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("*",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 Star pattern in JAVA, C++, PYTHON
Program to print right angle triangle number pattern in JAVA, C++ And Python