Q. Write a program in C to display the following output:
1 | ||||||
2 | 1 | 2 | ||||
3 | 2 | 1 | 2 | 3 | ||
4 | 3 | 2 | 1 | 2 | 3 | 4 |
3 | 2 | 1 | 2 | 3 | ||
2 | 1 | 2 | ||||
1 |
Ans.
/*c program for quadrilateral number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
int num=4,r,c,z,sp;
for(r=1; num>=r; r++)
for(r=1; num>=r; r++)
{
for(sp=num-r; sp>=1; sp--)printf(" ");
for(c=r; c>=1; c--)
printf("%d",c);
for(z=2; z<=r; z++)
printf("%d",z);
printf("\n");
}
for(r=1; num>=r; r++)
{
for(sp=r; sp>=1; sp--)
printf(" ");
for(c=num-r; c>=1; c--)
printf("%d",c);
for(z=2; z<=num-r; z++)
printf("%d",z);
printf("\n");
}
getch();
return 0;
}
/******************Output*****************
1 | ||||||
2 | 1 | 2 | ||||
3 | 2 | 1 | 2 | 3 | ||
4 | 3 | 2 | 1 | 2 | 3 | 4 |
3 | 2 | 1 | 2 | 3 | ||
2 | 1 | 2 | ||||
1 |
No comments:
Post a Comment