Character structure

Q. Write a C program to print the following character pyramid:
OR
Q. Write a C program to generate the following character structure:
A
BB
CCC
DDDD
CCC
BB
A


Ans.


/*c program for print above character structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
  char ch,r,c,z;
  printf("Enter any character : ");
  scanf("%c", &ch);
  if(ch>='a' && ch<='z')
    ch=ch-32;
  for(r='A'; r<=ch; r++)
  {
     for(c='A'; c<=r; c++)
        printf("%c",r);
     printf("\n");
  }
  for(z=ch-1; z>='A'; z--)
  {
     for(c='A'; c<=z; c++)
        printf("%c",z);
     printf("\n");
  }
  getch();
  return 0;
}
Output:-
Enter any character : d

A
BB
CCC
DDDD
CCC
BB
A

Comments