2.01.2012

Character triangle equal

Q. Write a C program for print the following character triangle:
OR
Q. Write a C program for print the following character pyramid:
A
BB
CCC
DDDD
EEEEE


Ans.




/*C program for character triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
  char ch,r,c;
  printf("Enter last pyramid character : ");
  ch=getchar();
  if(ch>='a' && ch<='z')
     ch=ch-32;
  for(r='A'; r<=ch; r++)
  {
     for(c='A'; c<=r; c++)
        printf("%c",r);
     printf("\n");
  }
  return 0;
}
Output:-
Enter last pyramid character : e

A
BB
CCC
DDDD
EEEEE

You might also like:

  1. Big 98+ C pyramid programs list
  2. Latest asking pyramid program list

14 comments:

  1. Can you do this. Need help please


    a
    bb
    ccc
    dddd

    ReplyDelete
    Replies
    1. #include
      #include
      int main()
      {
      char ch,r,c;
      printf("Enter last pyramid character : ");
      ch=getchar();
      if(ch>='A' && ch<='Z')
      ch=ch+32;
      for(r='a'; r<=ch; r++)
      {
      for(c='a'; c<=r; c++)
      printf("%c",r);
      printf("\n");
      }
      return 0;
      }

      Delete
  2. Replies
    1. @ Anto,

      Your required above program is :

      http://cprogrammingcodes.blogspot.in/2014/01/decrease-character-pyramid.html

      Delete
  3. #include

    int main()
    {
    int i,j;
    char ch='A';

    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {
    printf("%c",ch);
    }
    printf("\n");
    ch++;
    }
    return 0;
    }

    ReplyDelete
  4. c
    co
    com
    comp
    compu
    comput
    compute
    computer
    hoe to get this output in c program

    ReplyDelete
    Replies
    1. @Vky Ganesan,

      the source code for above character pattern as following:

      #include"stdio.h"
      #include"conio.h"
      int main()
      {
      int x,y;
      static char str[]="computer";
      for(x=0; x<8; x++)
      {
      y=x+1;
      printf("%-5.*s\n",y,str);
      }

      getch();
      return 0;
      }

      Delete
  5. Aa
    Bb Bb
    Cc Cc Cc
    Dd Dd Dd Dd

    how to get this output in c program

    ReplyDelete
    Replies
    1. @Ketan Bande

      Your required character pattern pyramid source code as following:

      #include"stdio.h"
      #include"conio.h"
      int main()
      {
      char ch,r,c,z='a';
      printf("Enter last pyramid character : ");
      ch=getchar();
      if(ch>='a' && ch<='z')
      ch=ch-32;
      for(r='A'; r<=ch; r++,z++)
      {
      for(c='A'; c<=r; c++)
      printf("%c%c ",r,z);
      printf("\n");
      }
      getch();
      return 0;
      }

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. a1
    a2 b3
    a4 b5 c6
    a7 b8 c9 d10

    ReplyDelete
  8. plz.provide the code for the pattern below

    zywxvwxyz
    zyxwxyz
    zyxyz
    zyz
    z

    ReplyDelete
  9. can you do this if we enter number 7
    its output is

    CDBAXYZ
    PQRSTU
    KLMNO
    GH IJ
    DEF
    CB
    A

    ReplyDelete
  10. Can you do
    A
    B B
    C C C
    D D D D

    With function?

    ReplyDelete