2.01.2012

Character triangle

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


 ABCDEDCBA
   BCDEDCB
      CDEDC
        DED
           E
Ans.
/* c program for character triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
  int sp;
  char ch,r,c;
  printf("Enter pyramid character : ");
  ch=getchar();
  if(ch>='a' && ch<='z')
    ch=ch-32;
  for(r='A'; r<=ch; r++)
  {
     for(sp=r; sp>'A'; sp--)
       printf(" ");
     for(c=r; c<=ch; c++)
       printf("%c",c);
     for(c=ch-1; r<=c; c--)
       printf("%c",c);
     printf("\n");
  }
  return 0;
}

Output:-

Enter pyramid character : e
ABCDEDCBA
 BCDEDCB
  CDEDC
   DED
    E

10 comments:

  1. can i have a program for this output
    input:n=4
    output:
    H
    HOH
    HOOOH
    HHHHHHH

    ReplyDelete
  2. Can i print the following output
    A B C D
    A B C
    A B
    A

    ReplyDelete
    Replies
    1. @Dilllip Kumar Jena,

      Your required character triangle pattern C program source code for above output as:

      http://cprogrammingcodes.blogspot.com/2015/08/character-triangle-shape-c-program.html

      Delete
  3. Replies
    1. @ amey tamhankar,

      your required character triangle shape C program print source code as:

      http://cprogrammingcodes.blogspot.com/2015/08/character-triangle-shape-c-program.html

      Delete
  4. How to print the output
    ABCDEFGHHGFEDCBA
    ABCDEFGGFEDCBA
    ABCDEFFEDCBA
    ABCDEEDCBA
    ABCDDCBA
    ABCCBA
    ABBA
    AA

    ReplyDelete
  5. How to print the output
    ABCDEFGHHGFEDCBA
    ABCDEFGGFEDCBA
    ABCDEFFEDCBA
    ABCDEEDCBA
    ABCDDCBA
    ABCCBA
    ABBA
    AA

    ReplyDelete
    Replies
    1. @ Shafiqah Cd

      Your required character pattern pyramid C program source code :

      http://www.cprogrammingcodes.blogspot.com/2012/09/character-pyramid.html

      Delete
  6. C
    BCB
    ABCBA
    BCB
    C
    give me the solution plsss.....

    ReplyDelete
    Replies
    1. # Dinesh

      Your required character triangle C program source code as:

      http://cprogrammingcodes.blogspot.com/2016/02/character-pattern-of-half-diamond.html

      Delete