Q. Write a C program to print character in following fashion.
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
Ans.
/*c program to print character rhombus structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
char ch,r,c,chh;
int sp;
printf("\nEnter any character : ");
scanf("%c",&ch);
if(ch>='a' && ch<='z')
ch=ch-32;
printf("\n");
for(r='A'; r<=ch; r++)
{
for(sp=ch-r; sp>=1; sp--)
printf(" ");
for(c='A'; c<=r; c++)
printf("%c",c);
for(c=r-1; c>='A'; c--)
printf("%c",c);
printf("\n");
}
for(r='A'; 'A'<=ch; ch--,r++)
{
for(sp=r; sp>='A'; sp--)
printf(" ");
for(c='A'; c<=ch-1; c++)
printf("%c",c);
for(c=ch-2; c>='A'; c--)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/********** OUTPUT ***********/
OR
Write a C program to print a character rhombus.A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
Ans.
/*c program to print character rhombus structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
char ch,r,c,chh;
int sp;
printf("\nEnter any character : ");
scanf("%c",&ch);
if(ch>='a' && ch<='z')
ch=ch-32;
printf("\n");
for(r='A'; r<=ch; r++)
{
for(sp=ch-r; sp>=1; sp--)
printf(" ");
for(c='A'; c<=r; c++)
printf("%c",c);
for(c=r-1; c>='A'; c--)
printf("%c",c);
printf("\n");
}
for(r='A'; 'A'<=ch; ch--,r++)
{
for(sp=r; sp>='A'; sp--)
printf(" ");
for(c='A'; c<=ch-1; c++)
printf("%c",c);
for(c=ch-2; c>='A'; c--)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/********** OUTPUT ***********/
CHARACTER RHOMBUS |
No comments:
Post a Comment