Print mirrored right triangle Alphabet pattern



   
    A
   AB
  ABC
 ABCD
ABCDE 
   

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


Sample Input/Output:-


Sample Input First:E

Sample Output First: 

    A
   AB
  ABC
 ABCD
ABCDE  

Sample Input Second: D


Sample Output Second: 

A AB ABC ABCD

Data requirement:-


  Input Data:- row_size


  Output Data:-p


  Additional Data:- out, in


Program in C

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


Code:

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

    for (p = 'A'p <= outp++)
      printf("%c"p);
    printf("\n");
  }
}


Input/Output:

Enter the row size(In Alphabet):E

    A
   AB
  ABC
 ABCD
ABCDE 

Program in C++

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


Code:

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


Input/Output:

Enter the row size(In Alphabet):D

A AB ABC ABCD


Program in Java

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


Code:

import java.util.Scanner;

public class MirroredRightTriangleAlphabetPattern {

    public static void main(String[] args) {
        Scanner cs = new Scanner(System.in);
        System.out.println("Enter the row size(In Alphabet):");
        int outinp;
        char row_size = cs.next().charAt(0);
        for (out = 'A'out <= row_sizeout++) {
            for (in = row_size - 1in >= outin--)
                System.out.print(" ");
            for (p = 'A'p <= outp++)
                System.out.print((charp);
            System.out.println();
        }
        cs.close();
    }
}


Input/Output:

Enter the row size(In Alphabet):F
     A
    AB
   ABC
  ABCD
 ABCDE
ABCDEF

Program in Python

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


Code:

row_size = input("Enter the row size(In Alphabet):")
for out in range(ord('A'), ord(row_size)+1):
    for i in range(ord(row_size)-1out-1, -1):
        print(" "end="")
    for p in range(ord('A'), out+1):
        print(chr(p), end="")
    print("\r")



Input/Output:

Enter the row size(In Alphabet):D

A AB ABC ABCD

Post a Comment

0 Comments