All for Joomla All for Webmasters

C Program to print Alphabet Triangle

There are different triangles that can be printed. Triangles can be generated by alphabets or numbers. In this c program, we are going to print alphabet triangles.

Let’s see the c example to print alphabet triangle.

  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main(void)
  4. {
  5.     int ch=65;
  6.     int i,j,k,m;
  7.    clrscr();
  8.     for(i=1;i<=5;i++)
  9.     {
  10.         for(j=5;j>=i;j–)
  11.             printf(” “);
  12.         for(k=1;k<=i;k++)
  13.             printf(“%c”,ch++);
  14.             ch–;
  15.         for(m=1;m<i;m++)
  16.             printf(“%c”,–ch);
  17.         printf(“\n”);
  18.         ch=65;
  19.     }
  20.    getch();
  21. }

Output:

     A
    ABA
   ABCBA
  ABCDCBA
 ABCDEDCBA
PinIt
submit to reddit

Leave a Reply

Top