Wednesday, January 29, 2014

Decrease Character Pyramid

Q. Write a C program to print the following decrease character pyramid as:

EEEEE
DDDD
CCC
BB
A

Ans.

/*c program for decrease number pyramid*/
#include<stdio.h>
int main()
{

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

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


Output for decrease character pyramid C program
Figure: Screen shot for decrease character pyramid C program

No comments:

Post a Comment