Q. Write a C program to print the following character pyramid as:
ABCD
BCDA
CDAB
DABC
Ans.
Cross-reference: Before you read answer of above program, i recommend to read Number Rectangle Program for easily understand this program.
/*c program for character pyramid*/
#include<stdio.h>
int main()
{
char ch,r,c,t;
printf("Enter any character : ");
scanf("%c", &ch);
if(ch>='a' && ch<='z')
ch = ch - 32;
for(r='A'; r<=ch; r++)
{
for(c=r; c<=ch; c++)
printf("%c",c);
for(t='A'; t<r; t++)
printf("%c",t);
printf("\n");
}
return 0;
}
The output of above program would be:
Figure: Screen shot for character rectangle pyramid C program |
Comments
Post a Comment