Character Pyramid Program

Selasa, 08 April 2014

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

ABCD

CDA
AB
C

Ans.

Cross-reference: Before you read answer of above program i recommend to read Number Pyramid Program for easily understand this program. 

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

 char ch=D,n,c,r,t;
 n=ch;
 for(r=A; r<=ch; r++,n--)
 {
  if(r==B || r==D)
  {
    for(c=A,t=C; c<=n; c++,t++)
    {
      if(c==C && r==B)
         printf("A");
      else
         printf("%c",t);
    }
  }
  else
  {
    for(c=A; c<=n; c++)
        printf("%c", c);
  }
  printf("
"
);

 }
 return 0;
}

The output of above program would be:


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

Related Posts by Categories

0 komentar:

Posting Komentar

Copyright © 2010 All About Tech Information | Powered By Blogger