Q. write a C program to display the character in following fashion:
A
BA
CBA
DCBA
EDCBA
DCBA
CBA
BA
A
Ans.
/* c program for square character triangle */
#include<stdio.h>
#include<conio.h>
int main()
{
char ch,r,c;
int sp;
printf("\nEnter last character of triangle : ");
scanf("%c",&ch);
if(ch>='a' && ch<='z')
ch=ch-32;
printf("\n");
for(r='A'; r<=ch; r++)
{
for(c=r; c>='A'; c--)
printf("%c",c);
printf("\n");
}
for(r='A'; 'A'<=ch; ch--,r++)
{
for(c=ch-1; c>='A'; c--)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
A
BA
CBA
DCBA
EDCBA
DCBA
CBA
BA
A
Ans.
/* c program for square character triangle */
#include<stdio.h>
#include<conio.h>
int main()
{
char ch,r,c;
int sp;
printf("\nEnter last character of triangle : ");
scanf("%c",&ch);
if(ch>='a' && ch<='z')
ch=ch-32;
printf("\n");
for(r='A'; r<=ch; r++)
{
for(c=r; c>='A'; c--)
printf("%c",c);
printf("\n");
}
for(r='A'; 'A'<=ch; ch--,r++)
{
for(c=ch-1; c>='A'; c--)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/************* OUTPUT **************/
No comments:
Post a Comment