Q. Write a C program to display the following character rectangle structure/pattern/design as:
ABCDEEDCBA
ABCD__DCBA
ABC____CBA
AB______BA
A________A
Ans.
/*c program for character rectangle pattern*/
#include<stdio.h>
int main()
{
char ch,r='A',c,sp;
printf("Enter any character : ");
scanf("%c",&ch);
if(ch>='a' && ch<='z')
ch=ch-32;
printf("\n");
for(; ch>='A'; ch--,r++)
{
for(c='A'; c<=ch; c++)
printf("%c",c);
for(sp=r; sp>'A'; sp--)
printf("__");
for(c=ch; c>='A'; c--)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/*************************************************************
ABCDEEDCBA
ABCD__DCBA
ABC____CBA
AB______BA
A________A
Ans.
/*c program for character rectangle pattern*/
#include<stdio.h>
int main()
{
char ch,r='A',c,sp;
printf("Enter any character : ");
scanf("%c",&ch);
if(ch>='a' && ch<='z')
ch=ch-32;
printf("\n");
for(; ch>='A'; ch--,r++)
{
for(c='A'; c<=ch; c++)
printf("%c",c);
for(sp=r; sp>'A'; sp--)
printf("__");
for(c=ch; c>='A'; c--)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/*************************************************************
The output of above program would be:
*************************************************************/Figure: Screen shot for character rectangle structure C program |
No comments:
Post a Comment