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