Showing posts with label c program for character pyramid. Show all posts
Showing posts with label c program for character pyramid. Show all posts

3.12.2012

Character triangle

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


EDCBA
DCBA
CBA
BA
A


Ans:


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


/****************OUTPUT****************/
Screen shot for character triangle

2.01.2012

Character structure

Q. Write a C program to print the following character pyramid:
OR
Q. Write a C program to generate the following character structure:
A
BB
CCC
DDDD
CCC
BB
A


Ans.


/*c program for print above character structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
  char ch,r,c,z;
  printf("Enter any character : ");
  scanf("%c", &ch);
  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");
  }
  for(z=ch-1; z>='A'; z--)
  {
     for(c='A'; c<=z; c++)
        printf("%c",z);
     printf("\n");
  }
  getch();
  return 0;
}
Output:-
Enter any character : d

A
BB
CCC
DDDD
CCC
BB
A

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

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