Print the Inverted Half Pyramid Alphabet Pattern



E E E E E D D D D C C C B B A
   

Problem Statement:- Program to Print the Inverted Half Pyramid Alphabet Pattern.


Sample Input/Output:-


Sample Input First:E

Sample Output First: 

E E E E E D D D D C C C B B
A  

Sample Input Second: D


Sample Output Second: 

D D D D C C C B B A

Data requirement:-


  Input Data:- row_size


  Output Data:- out


  Additional Data:- in


Program in C

Here is the source code of the C Program to Print the Inverted Half Pyramid Alphabet Pattern.


Code:

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


Input/Output:

Enter the row size(In Alphabet):E

E E E E E

D D D D

C C C

B B

A


Program in C++

Here is the source code of the C++ Program to Print the Inverted Half Pyramid Alphabet Pattern.


Code:

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


Input/Output:

Enter the row size(In Alphabet):D

D D D D 

C C C

B B

A


Program in Java

Here is the source code of the Java Program to Print the Inverted Half Pyramid Alphabet Pattern.


Code:

import java.util.Scanner;

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


Input/Output:

Enter the row size(In Alphabet):F

F F F F F F 

E E E E E 

D D D D 

C C C 

B B 

Program in Python

Here is the source code of the Python Program to Print the Inverted Half Pyramid Alphabet Pattern.


Code:

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


Input/Output:

Enter the row size(In Alphabet):E E E E E E D D D D C C C B B A

Post a Comment

0 Comments