*
**
***
****
*****
Problem Statement:- Program to print the right triangle star pattern.
Sample Input/Output:-
Data requirement:-
Input Data:- row_size
Output Data:- *
Additional Data:- in,out,p
Program in C
Here is the source code of the C Program to display the right triangle star pattern.
Code:
#include <stdio.h>int main(){ int row_size, in, out; printf("Enter the row size:"); scanf("%d", &row_size); for (out = 1; out <= row_size; out++) { for (in = 1; in <= out; in++) printf("*"); printf("\n"); }}
Input/Output:
Enter
the row size:5
*
**
***
****
*****
Program in C++
Here is the source code of the C++ Program to print the right triangle star pattern.
Code:
#include <iostream>using namespace std;int main()
{ int row_size; cout << "Enter the row size:"; cin >> row_size;
for (int out = 1; out <= row_size; out++) { for (int in = 1; in <= out; in++) cout << "*"; cout << "\n"; }}
Input/Output:
Enter
the row size:7
*
**
***
****
*****
******
*******
Program in Java
Here is the source code of the Java Program to display the right triangle star pattern.
Code:
import java.util.Scanner;public class RightTriangleStarPattern { public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter the row size:"); int row_size = sc.nextInt(); for (int out = 1; out <= row_size; out++) { for (int in = 1; in <= out; in++) System.out.printf("*");
System.out.println(); } sc.close(); }}
Input/Output:
Enter the row size:5
*
**
***
****
*****
Program in Python
Here is the source code of the Python Program to print the right triangle star pattern.
Code:
row_size = int(input("Enter the row size:"))for out in range(row_size+1): for j in range(out): print("*", end="") print("\r")
Input/Output:
Enter the row size:
9
*
**
***
****
*****
******
*******
********
*********
0 Comments
Please do not Enter any spam link in the comment box