Q. Write a C program to print the Z-Shape pyramid as:
******
*
*
*
*
******
Ans.
/*c pyramid program for z-shape*/
#include<stdio.h>
int main()
{
int num,r,c,sp,n;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
printf("*");
printf("\n");
for(r=1,n=num-1; r<=num-2; r++,n--)
{
for(sp=1; sp<n; sp++)
printf(" ");
printf("*");
printf("\n");
}
for(r=1; r<=num; r++)
printf("*");
printf("\n");
getch();
return 0;
}
The output of above program would be:
******
*
*
*
*
******
Ans.
/*c pyramid program for z-shape*/
#include<stdio.h>
int main()
{
int num,r,c,sp,n;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
printf("*");
printf("\n");
for(r=1,n=num-1; r<=num-2; r++,n--)
{
for(sp=1; sp<n; sp++)
printf(" ");
printf("*");
printf("\n");
}
for(r=1; r<=num; r++)
printf("*");
printf("\n");
getch();
return 0;
}
The output of above program would be:
Figure : Screen shot for Z-Shape pyramid C program |
Comments
Post a Comment