Wednesday, 15 May 2013

Dignal Character Pyramid

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

 a b b b
 b a b b
 b b a b
 b b b a

Ans.

/*c program for alternate character pyramid*/
#include<stdio.h>
int main()
{
 char r,c,ch='d';

 for(r='a'; r<=ch; r++)
 {
  for(c='a'; c<=ch; c++)
  {
    if(r==c)
       printf(" a");
    else
       printf(" b");
  }
  printf("\n");
 }
 getch();
 return 0;
}

The output of above program would be:


Output of dignal equal pyramid C program
Figure: Screen shot for dignal equal pyramid C program

Related program:

1. Print the following dignal number pyramid:

  1 2 2 2
  2 1 2 2
  2 2 1 2
  2 2 2 1

No comments:

Post a Comment