Program in C to print the character pyramid

Write a program in C to print the following character pyramid:

ABCD
CDA
AB
C

Solution:
#include<stdio.h>
int main()
{
char ch='D',n,c,r,t;
n=ch;
for(r='A'; r<=ch; r++,n--)
{
if(r=='B' || r=='D')
{
for(c='A',t='C'; c<=n; c++,t++)
{
if(c=='C' && r=='B')
printf("A");
else
printf("%c",t);
}
}
else
{
for(c='A'; c<=n; c++)
printf("%c", c);
}
printf("\n");
}
return 0;
}


Post a Comment