Print mirrored right triangle Alphabet pattern

         A
      BB
    CCC
  DDDD
EEEEE


Problem Statement:- Program to print mirrored right triangle Alphabet pattern.

Sample Input/Output:-


Sample Input First:E

Sample Output First: 

      A
   BB
  CCC
 DDDD
EEEEE

Sample Input Second: D


Sample Output Second: 

        A
   BB
  CCC
 DDDD

Data requirement:-


  Input Data:- row_size


  Output Data:- out


  Additional Data:- in, p


Program in C

Here is the source code of the C Program to print a mirrored right triangle Alphabet pattern.


Code:


#include<stdio.h>
int main()
{
  printf("Enter the row and column size:");
  int out,in,p;
  char row_size;
  scanf("%c",&row_size);
  for(out='A';out<=row_size;out++)
  {
   for(in=row_size-1;in>=out;in--)
    printf(" ");

    for(p='A';p<=out;p++)

        printf("%c",out);
   printf("\n");
  }
}

Input/Output:
Enter the row and column size:E
    A
   BB
  CCC
 DDDD
EEEEE

Program in C++

Here is the source code of the C++ Program to print a mirrored right triangle Alphabet pattern.


Code:


#include<iostream>
using namespace std;
int main()
{
  cout<<"Enter the row and column size:";
  int out,in,p;
  char row_size;
  cin>>row_size;
   for(out='A';out<=row_size;out++)
  {
   for(in=row_size-1;in>=out;in--)
    cout<<" ";
   for(p='A';p<=out;p++)
    cout<<char(out);
        cout<<"\n";
}}

Input/Output:
Enter the row and column size:D
    A
   BB
  CCC
 DDDD

Program in Java

Here is the source code of the Java Program to print a mirrored right triangle Alphabet pattern.


Code:


import java.util.Scanner;
public class p22 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);    
    System.out.println("Enter the row and column size:");
    int out,in,p;
    char row_size=cs.next().charAt(0);
    for(out='A';out<=row_size;out++)
    {
     for(in=row_size-1;in>=out;in--)
     System.out.print(" ");
     for(p='A';p<=out;p++)
     System.out.print((char)out);
     System.out.println();
    }
    cs.close();
}
}

Input/Output:
Enter the row and column size:
E
    A
   BB
  CCC
 DDDD
EEEEE

Program in Python

Here is the source code of the Python Program to print a mirrored right triangle Alphabet pattern.


Code:


print("Enter the row and column size:");
row_size=input()
for out in range(ord('A'),ord(row_size)+1):
    for i in range(ord('A'),out+1):
        print(chr(i),end=" ")
    print("\r")

Input/Output:
Enter the row and column size:

Post a Comment

0 Comments