Monday, April 7, 2014

Quadrilateral pyramid

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(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("
"
);
 }
 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("
"
);
 }
 getch();
 return 0;
}


/******************Output*****************



1




212


32123
4321234

32123


212




1


***************************************/

Related Post:

0 comments:

Post a Comment

 
Copyright 2009 Information Blog
Powered By Blogger