C Programming

C Programming


How To Design Taj Mahal Shape Pyramid

Posted: 01 Feb 2015 04:11 AM PST

Q. Write a C program to print the following Taj Mahal Shape pyramid as:

*
***
*****
*******
**
****
******
*******
******
****
**
*******
*****
***
*

Ans.

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

 int r,c,w,x,y,z;
 for(r=1,z=1; r<=4; r++,z=z+2)
 {
   for(c=1; c<=z; c++)
       printf("*");
   printf("\n");
 }
 for(r=1,y=2; r<=3; r++,y=y+2)
 {
   for(c=1; c<=y; c++)
       printf("*");
   printf("\n");
 }
 for(r=1; r<=7; r++)
    printf("*");
 printf("\n");
 for(r=1,x=6; r<=3; r++,x=x-2)
 {
   for(c=1; c<=x; c++)
       printf("*");
   printf("\n");
 }
 for(r=1,w=7; r<=4; r++,w=w-2)
 {
   for(c=1; c<=w; c++)
       printf("*");
   printf("\n");
 }
 getch();
 return 0;
}

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

Output of Taj Mahal shape pyramid source code C programming
Figure: Screen shot for Taj Mahal shape pyramid source code C program


You might also like:

  1. Big list of 98+ C Pyramid Programs
  2. Latest Pyramid Programs List asked by users


Post a Comment