Thursday, February 6, 2014

Equal Character Triangle

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

A
BAB
CBABC
DCBABCD
EDCBABCDE

Ans.

/*c program for Equal Character Triangle pattern*/
#include<stdio.h>
int main()
{

 char ch,r,c;
 printf("Enter Any Character : ");
 scanf("%c", &ch);
 if(ch>='a' && ch<='z')
    ch=ch-32;
 for(r='A'; r<=ch; r++)
 {
   for(c=r; c>='A'; c--)
      printf("%c",c);
   for(c='B'; c<=r; c++)
      printf("%c",c);
   printf("\n");
 }
 getch();
 return 0;
}

/*********************************************
The output of above program would be:
********************************************/


Output of equal character triangle C program
Figure: Screen shot for equal character triangle C program


Related Program:

Equal Number Triangle C program:

1
212
32123
4321234
543212345

No comments:

Post a Comment