Print the Full Pyramid Alphabet Pattern

        A

     BBB

   CCCCC

 DDDDDDD

EEEEEEEEE



Problem Statement:- Program to print the Full Pyramid Alphabet Pattern.

Sample Input/Output:-


Sample Input First:5

Sample Output First: 

        A
      BBB
   CCCCC
  DDDDDDD
EEEEEEEEE

Sample Input Second: 4


Sample Output Second: 

      A
    BBB
  CCCCC
DDDDDDD

Data requirement:-

   
  Input Data:- row_size

  Output Data:-out

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

Program in C

Here is the source code of the C Program to print the Full Pyramid Alphabet Pattern.

Code:

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

Input/Output:
Enter the row size:5
        A
      BBB
   CCCCC
  DDDDDDD
EEEEEEEEE

Program in C++

Here is the source code of the C++ Program to print the Full Pyramid Alphabet Pattern.

Code:

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

Input/Output:
Enter the row size:4
      A
    BBB
  CCCCC
DDDDDDD


Program in Java

Here is the source code of the Java Program to print the Full Pyramid Alphabet Pattern.

Code:

import java.util.Scanner;
public class AlphabetPattern15 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);

    System.out.println("Enter the row size:");
    int row_size=cs.nextInt();
        int np=1,in,out;
    for(out=0;out<row_size;out++)
    {
     for(in=row_size-1;in>out;in--)
      System.out.printf(" ");
     for(int p=0;p<np;p++)
      System.out.print((char)(out+65));
     np+=2;
     System.out.println();

    }
    cs.close();
}
}

Input/Output:
Enter the row size:
5
        A
      BBB
    CCCCC
  DDDDDDD
EEEEEEEEE

Program in Python

Here is the source code of the Python Program to print the Full Pyramid Alphabet Pattern.

Code:

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

Input/Output:
Enter the row size:3
     A
   BBB
CCCCC

Post a Comment

1 Comments

Please do not Enter any spam link in the comment box