Print the Alphabet Inverted Half Pyramid Pattern

EEEEE
  DDDD
    CCC
       BB
         A

 Write a C Program to print the Alphabet Inverted Half Pyramid Pattern

Solution In C

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=row_size;out>='A';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
EEEEE
  DDDD
    CCC
       BB
         A

Write a C++ Program to print the Alphabet Inverted Half Pyramid Pattern


Solution In C++

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=row_size;out>='A';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
DDDD
  CCC
     BB
        A

Write a Java Program to print the Alphabet Inverted Half Pyramid Pattern

Solution In Java

Code:

import java.util.Scanner;
public class p24 {

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=row_size;out>='A';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
EEEEE
  DDDD
    CCC
       BB
         A

Write a Python Program to print the Alphabet Inverted Half Pyramid Pattern

Solution In Python

Code:

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


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

Post a Comment

0 Comments