Program to print the Solid Half Diamond Alphabet Pattern

 F

FE

FED

FEDC

FEDCB

FEDCBA

FEDCB

FEDC

FED

FE

F


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

 Data requirement:-

   Input Data:- row_size

  Output Data:-in or inn(for python)

  Additional Data:-out

Program in C

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

Code:

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

Input/Output:
Enter the row size:5
F
FE
FED
FEDC
FEDCB
FEDCBA
FEDCB
FEDC
FED
FE
F

Program in C++

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

Code:

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

Input/Output:
Enter the row size:4
E
ED
EDC
EDCB
EDCBA
EDCB
EDC
ED
E

Program in Java

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

Code:

import java.util.Scanner;
public class AlphabetPattern17 {

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

Input/Output:
Enter the row size:
5
F
FE
FED
FEDC
FEDCB
FEDCBA
FEDCB
FEDC
FED
FE
F

Program in Python

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

Code:

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

Input/Output:
Enter the row size:3
D
DC
DCB
DCBA
DCB
DC
D

Post a Comment

0 Comments