Wednesday, February 1, 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

No comments:

Post a Comment