Showing posts with label character triangle. Show all posts
Showing posts with label character triangle. Show all posts

9.02.2012

Character Pyramid

Q. Write a C program for following character triangle.
or
Q. Write a C program for print the following character pyramid.

ABCDEFFEDCBA
ABCDEEDCBA
ABCDDCBA
ABCCBA
ABBA
AA

Ans.

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


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

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

Related Programs:

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

       123456654321
       1234554321
       12344321
       123321
       1221
       11


You Might Also Like:

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

2.15.2012

Square triangle4

Q. write a C program to display the character in following fashion:
A
BA
CBA
DCBA
EDCBA
DCBA
CBA
BA
A


Ans.


/* c program for square character triangle */

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

/************* OUTPUT **************/