Character triangle

Q. Write a C program to print the following character triangle:


EDCBA
DCBA
CBA
BA
A


Ans:


/*c program for display the character triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 char ch,r,c;
 int sp;
 printf("Enter last character of triangle : ");
 scanf("%c",&ch);
 if(ch>='a' && ch<='z')
    ch=ch-32;
 printf("\n");
 for(r='A'; r<=ch; ch--)
 {
   for(c=ch; c>=r; c--)
       printf("%c",c);
   printf("\n");
 }
 getch();
 return 0;
}


/****************OUTPUT****************/
Screen shot for character triangle

Comments