Q. write a C program to display the character in following fashion:
A
AB
ABC
ABCD
ABCDE
ABCD
ABC
AB
A
Ans.
#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(sp=ch-r; sp>=1; sp--)
printf(" ");
for(c='A'; c<=r; c++)
printf("%c",c);
printf("\n");
}
for(r='A'; 'A'<=ch-1; ch--,r++)
{
for(sp=r; sp>='A'; sp--)
printf(" ");
for(c='A'; c<ch; c++)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/***************** OUTPUT ********************/
A
AB
ABC
ABCD
ABCDE
ABCD
ABC
AB
A
Ans.
#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(sp=ch-r; sp>=1; sp--)
printf(" ");
for(c='A'; c<=r; c++)
printf("%c",c);
printf("\n");
}
for(r='A'; 'A'<=ch-1; ch--,r++)
{
for(sp=r; sp>='A'; sp--)
printf(" ");
for(c='A'; c<ch; c++)
printf("%c",c);
printf("\n");
}
getch();
return 0;
}
/***************** OUTPUT ********************/
Comments
Post a Comment