Alphabet Pattern

Cpp program to generate Alphabet pyramid

Cpp program to generate Alphabet pyramid using the while loop

In this tutorial, we will discuss Cpp program to generate Alphabet pyramid using the while loop

Alphabet Pyramid pattern in C++ using while loop

Alphabet pyramid using while loop

In this Article, we are going to learn about how to display  Alphabet pyramid pattern  using while loop  in C++ programming language

Here, we display some  Alphabet pyramid pattern program with coding using nested while loop and also we get input from the user using cin in C++ language

The user can provide numbers as they wish and get the  Alphabet pyramid pattern according to their input.

Alphabet pyramid pattern 1

Program 1

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    cout << "Enter the number of rows:" << endl;
    cin>>rows;
    i=1;
while(i<=rows){//outer while loop
j=1;
  while(j<=rows-i){//inner while loop
  cout<<" ";//print space
  j++;
  }


   j=1;
   while(j<=i){//print left site pattern
  cout<<(char)(j+64);
   j++;
    }

   j=i-1;
   while(j>=1){//print right site pattern
  cout<<(char)(j+64);
   j--;
}
i++;
cout<<"\n";//move to next line
}
getch();
return 0;
}

When the above code is executed, it produces the following results

Enter the number of rows
6
          A
        ABA
      ABCBA
    ABCDCBA
  ABCDEDCBA
ABCDEFEDCBA

Program 2

Alphabet pyramid pattern 2

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows\n";
    cin>>rows;
    i=1;
while(i<=rows){//outer while loop
j=1;
  while(j<=rows-i){
  cout<<" ";//print space
  j++;
  }


   j=i;
   while(j>0){
  cout<<(char)(j+64);//print left site pattern
   j--;
    }

   j=2;
   while(j<=i){
 cout<<(char)(j+64);//print right site pattern
   j++;
}
i++;
cout<<"\n";//move to next line
}
getch();
    return 0;
}

 

When the above code is executed, it produces the following results

Enter the number of rows
6
          A
        BAB
      CBABC
    DCBABCD
  EDCBABCDE
FEDCBABCDEF

Alphabet pyramid pattern 3

Program 3

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
     int i,j,rows;
    cout<<"Enter the number of rows\n";
    cin>>rows;

i=1;
while(i<=rows){//outer while loop
j=1;
  while(j<=rows-i){
  cout<<" ";//print space
  j++;
  }


   j=1;
   while(j<=i){
  cout<<(char)(j+64);
  cout<<" ";
   j++;
    }
    i++;
    cout<<"\n";//move to next line
}
getch();
    return 0;
}

 

When the above code is executed, it produces the following results

Enter te number of rows
6
          A
        A B
      A B C
    A B C D 
  A B C D E
A B C D E F

Alphabet pyramid pattern 4

Program 4

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
     int i,j,rows;
    cout<<"Enter the number of rows\n";
    cin>>rows;

i=1;
while(i<=rows){
j=1;
  while(j<=rows-i){
  cout<<" ";
  j++;
  }


   j=1;
   while(j<=i){
  cout<<(char)(i+64);
  cout<<" ";
   j++;
    }
    i++;
    cout<<"\n";
}
getch();
    return 0;
}

 

When the above code is executed, it produces the following results

Enter the number of rows
6
          A
        B B
      C C C
    D D D D
   E E E E E
  F F F F F F

Alphabet pyramid pattern 5

Program 5

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int i,j,rows;
    cout<<"Enter the number of rows\n";
    cin>>rows;//get input from user

i=rows;
while(i>=1){
j=1;
  while(j<=rows-i){
 cout<<"  ";  //print space of initial
  j++;
  }


   j=1;
   while(j<=2*i-1){
       if(j<=i){
  cout<<(char)(j+64);//print alphabet
  cout<<" ";
       }
      else{
          cout<<(char)(2*i-j+64);
          cout<<" ";
      }
   j++;
    }
    i--;
    cout<<"\n";//move to next line
}
getch();
    return 0;
}

 

When the above code is executed, it produces the following results

Enter the  number of rows
5
A B C D E D C B A
    A B C D C B A
        A B C B A
            A B A
                A

 

Suggested for you

Operator in C++ language

Data type  in C++ language

While loop in C++ language

Nested while loop in C++ language

Alphabet Pyramid pattern in Java using while loop
Alphabet Pyramid pattern in C using while loop
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

Explanation of one dimensional array (Data structure)

Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…

2 days ago

Python program to calculate the sum of odd and even numbers in a list

Python program to calculate the sum of odd and even numbers in a list In…

5 days ago

Python code to Calculate sum of odd and even in a list

Python code to Calculate sum of odd and even in a list In this tutorial,…

1 week ago

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

2 weeks ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

1 month ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

2 months ago