Showing posts with label pyramid. Show all posts
Showing posts with label pyramid. Show all posts

Friday, April 11, 2014

Square Star Pyramid

Q. Write a C program to print the square star pyramid design as:

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

Ans.

/*c program for star square design*/
#include<stdio.h>
int main()
{
 int cols,rows,r,c,sp;
 printf("Enter no. of columns: ");
 scanf("%d", &cols);
 printf("Enter no. of rows: ");
 scanf("%d", &rows);
 for(r=1; r<=cols; r++)
 {
  if(r==1 || r==cols)
      printf(" ");
  else
      printf("*");
 }
 printf("
"
);

 for(c=1; c<=rows-2; c++)
 {
   printf("*");
   for(sp=1; sp<=cols-2; sp++)
       printf(" ");
   printf("*
"
);

 }
 for(r=1; r<=cols; r++)
 {
   if(r==1 || r==cols)
       printf(" ");
   else
       printf("*");
 }
 getch();
 return 0;
}

The output of above program would be:

Output of Square Star Pyramid C program
Figure: Screen shot for Square Star Pyramid C program
Read More..

Wednesday, April 9, 2014

Rectangle number pyramid

Q. Write a C program for print the following number design or number pyramid or number rectangle:

33333
32223
32123
32223
33333

Ans.

To make the above program make module/program and add all module(tips):
Make 3 parts of the design and write down code and at the end, add all parts/module
Figure: How to write above program tips


/*c program for print number rectangle pyramid*/
#include<stdio.h>
int main()
{
 int i,j,k,n=3,r;
 for(j=1; j<=5; j++)
    printf("%d",n);
 printf("
"
);

 for(r=1; r<=3; r++)
 {
  for(i=3; i>=2; i--)
    printf("%d", i);
  for(k=n-r; k>=0; k--)
  {
    if(k==0)
      printf("2");
    else
    {
      printf("%d",k);
      break;
    }
  }
  for(i=2; i<=3; i++)
     printf("%d",i);
  printf("
"
);

 }
 for(j=1; j<=5; j++)
     printf("%d",n);
 return 0;
}

The output of above program would be:
Output of rectangle number pyramid C program
Screen shot for rectangle number pyramid C program


Read More..

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


***************************************/
Read More..
 
Copyright 2009 Information Blog
Powered By Blogger