Saturday, July 5, 2014

Inverted Pyramid of Characters

Let's try to write a program which will print an inverted pyramid of character like this if we give input as 4

ABCDCBA
   ABCBA
      ABA
         A

#include<stdio.h>

int main()

{

 int rows,i,j,k;

printf("enter the number of rows you want to print \n");
scanf("%d",&rows);

for(i=0;i<rows;i++)
{
  
  
    for(j=0;j<i;j++)
    {
        printf(" ");
    }
  
    for(k=0;k<((rows-1)-i);k++)
    {
        printf("%c ",(65+k));
    }
  
    for(;k>=0;k--)
    {
    printf("%c ",(65+k));
    }
    printf("\n");
}


No comments:

Post a Comment