C program to print reverse pyramid of alphabets

Mr Coder August 26, 2012 0




C program to print reverse pyramid of alphabets :  In my previous two programs, we have seen that how to create pyramid using stars and pyramid using numbers (also called Pascal’s triangle). Now, we will learn how to extend that logic to make a reverse pyramid of alphabets. Logic will be somewhat similar to previous two programs but we need to include default value of alphabets using ASCII conversion format and then use those in our logic. This C program to print reverse pyramid of alphabets takes number of rows from user as its input and then displays a cool reverse pyramid made up of alphabets.

Let us see how to write a C program to print reverse pyramid of alphabets that takes number of rows in pyramid as user input and displays reverse alphabetical pyramid.

C program to print reverse pyramid of alphabets :

#include<stdio.h>
#include<conio.h>
int main( )
{
  int r,c,askey,sp,num;
  printf("------------------------------------------------------------------\n");
  printf("-------------------made by C code champ --------------------------\n");
  printf("------------------------------------------------------------------\n");
  printf("\n\n\tC PROGRAM TO PRINT REVERSE PYRAMID OF ALPHABETS \n");  
  printf("\nEnter the number of rows you want to show in your reverse pyramid : ");
  scanf("%d",&num);
  printf("\n\n\n");
  for( r=num; r>=1; r-- )
  {
    printf("\t");
    for(sp=num-1; sp>=r; sp--)
        printf("  "); //2 spaces

    askey=65;
    for(c=1; c<=r; c++ )
      printf("%2c", askey++ );
    --askey;
    for(c=r-1; c>=1; c-- )
       printf("%2c", --askey);

   printf("\n");
  }
  getch();
}

We hope that you all have enjoyed C code to print reverse pyramid of alphabets in C language. If you have any queries or issues regarding above code or logic ask us in form of comments.

Leave A Response »