Program to print the Solid Inverted Half Diamond Alphabet Pattern

               F

            EF

         DEF

      CDEF

   BCDEF

ABCDEF

   BCDEF

     CDEF

       DEF

         EF

           F



Problem statement:-  Program to print the Solid Inverted Half Diamond Alphabet Pattern.

 Data requirement:-

   Input Data:- row_size

  Output Data:- p

  Additional Data:-out, in or inn(for python)

Program in C

Here is the source code of the C  Program to print the Solid Inverted Half Diamond Alphabet Pattern.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    int out,in,p;
    printf("Enter the row size:");
    int row_size;
    scanf("%d",&row_size);
    for(out=row_size;out>=-row_size;out--)
    {
     for(in=1;in<=abs(out);in++)
     {
    printf(" ");
     }
     for(p=abs(out);p<=row_size;p++)
     printf("%c",p+65);
         printf("\n");
}}

Input/Output:
Enter the row size:5
              F
           EF
        DEF
     CDEF
   BCDEF
ABCDEF
  BCDEF
    CDEF
      DEF
        EF
          F

Program in C++

Here is the source code of the C++ Program to print the Solid Inverted Half Diamond Alphabet Pattern.

Code:

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

Input/Output:
Enter the row size:4
           E
        DE
     CDE
   BCDE
ABCDE
  BCDE
    CDE
      DE
         E

Program in Java

Here is the source code of the Java  Program to print the Solid Inverted Half Diamond Alphabet Pattern.

Code:

import java.util.Scanner;
public class AlphabetPattern18 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int out,in,p;
    System.out.println("Enter the row size:");
    int row_size=cs.nextInt();
    for(out=row_size;out>=-row_size;out--)
    {
     for(in=1;in<=Math.abs(out);in++)
     {
    System.out.printf(" "); 
     }
     for(p=Math.abs(out);p<=row_size;p++)
     System.out.print((char)(p+65));
    System.out.println();
    }
    cs.close();
}
}

Input/Output:
Enter the row size:
5
               F
            EF
         DEF
      CDEF
   BCDEF
ABCDEF
  BCDEF
    CDEF
      DEF
        EF
          F


Program in Python

Here is the source code of the Python Program to print the Solid Inverted Half Diamond Alphabet Pattern.

Code:

row_size=int(input("Enter the row size:"))
for out in range(row_size,-(row_size+1),-1):
    for in1 in range(1,abs(out)+1):
        print(" ",end="")
    for p in range(abs(out),row_size+1):
        print((chr)(p+65),end="")
    print("\r")

Input/Output:
Enter the row size:3
       D
     CD
   BCD
ABCD
  BCD
    CD
      D

Post a Comment

0 Comments