Number Character Pyramid

Q. Write a C program to print the following number character pyramid.

1
AB
123
ABCD
12345

Ans.

/*c program for number character pyramid*/
#include<stdio.h>
int main()
{
 int num=5,r,c;
 char ch;
 for(r=1; r<=num; r++)
 {
  if(r==2 || r==4)
  {
   ch='A';
   for(c=1; c<=r; c++,ch++)
     printf("%c",ch);
  }
  else
  {
   for(c=1; c<=r; c++)
     printf("%d",c);
  }
  printf("\n");
 }
 return 0;
}

The output of above program would be:


Output of number character pyramid C program
Figure: Screen shot for number character pyramid C program

Comments