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;
}
You might also like:
*
***
*****
*******
**
****
******
*******
******
****
**
*******
*****
***
*
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:
**********************************************************/
Figure: Screen shot for Taj Mahal shape pyramid source code C program |
You might also like:
No comments:
Post a Comment