Program to print right triangle star pattern

  *       
  **     
  *** 
  ****
  *****

Problem Statement:- Program to print the right triangle star pattern.

Sample Input/Output:-


Sample Input First:5

Sample Output First: 

*
**
***
****
*****

Sample Input Second: 7


Sample Output Second: 

*
**
***
****
*****
******
*******

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_sizeinout;
    printf("Enter the row size:");
    scanf("%d", &row_size);
    for (out = 1out <= row_sizeout++)
    {
        for (in = 1in <= outin++)
            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 = 1out <= row_sizeout++)
    {
        for (int in = 1in <= outin++)
            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 scnew Scanner(System.in);
        System.out.println("Enter the row size:");
        int row_size = sc.nextInt();
        for (int out = 1out <= row_sizeout++)
        {
            for (int in = 1in <= outin++)
                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
*
**
***
****
*****
******
*******
********
*********






Post a Comment

0 Comments