Alphabet Pattern

Alphabet Pyramid pattern in C using while loop

Alphabet Pyramid pattern in C using while loop

In this tutorial, we will discuss the Alphabet Pyramid pattern in C using while loop

Alphabet Pyramid pattern in C using the while loop

Alphabet Pyramid pattern in C

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

Here, we display an Alphabet pyramid pattern program with coding using nested while loop and also we get input from the user using scanf() function in C language

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

Program 1

Alphabet pyramid pattern 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);//get input from user
    i=1;
while(i<=rows){
j=1;
  while(j<=rows-i){
  printf(" ");//print space
  j++;
  }


   j=1;
   while(j<=i){//print left side pattern
  printf("%c",(char)(j+64));
   j++;
    }

   j=i-1;
   while(j>=1){//print right side pattern
  printf("%c",(char)(j+64));
   j--;
}
i++;
printf("\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

 

Alphabet pyramid pattern 2

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    i=1;
while(i<=rows){
j=1;
  while(j<=rows-i){
  printf(" ");//print space
  j++;
  }


   j=i;
   while(j>0){
  printf("%c",(char)(j+64));//print left side pattern
   j--;
    }

   j=2;
   while(j<=i){
 printf("%c",(char)(j+64));//print right side pattern
   j++;
}
i++;
printf("\n");
}
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 <stdio.h>
#include <stdlib.h>

int main()
{
     int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);

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


   j=1;
   while(j<=i){
  printf("%c",(char)(j+64));
  printf(" ");
   j++;
    }
    i++;
    printf("\n");
}
    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 <stdio.h>
#include <stdlib.h>

int main() {
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);
    i=1;
    while(i<=rows)
        {
            j=1;
    while(j<=rows-i){
            printf(" ");
    j++; }
    j=1;
    while(j<=i){
            printf("%c",(char)(i+64));
    printf(" ");
    j++; }
    i++;
    printf("\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 <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,rows;
    printf("Enter the number of rows\n");
    scanf("%d",&rows);

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


   j=1;
   while(j<=2*i-1){
       if(j<=i){
  printf("%c",(char)(j+64));
  printf(" ");
       }
      else{
          printf("%c",(char)(2*i-j+64));
          printf(" ");
      }
   j++;
    }
    i--;
    printf("\n");
}
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

 

Cpp program to generate Alphabet pyramid
Hollow Pyramid Pattern in Java using nested while
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

C# inverted full pyramid star pattern

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

3 weeks ago

C# Full Pyramid star pattern program

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

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

1 month ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

1 month ago