Showing posts with label 1 121 12321 1234321 12321 121 1. Show all posts
Showing posts with label 1 121 12321 1234321 12321 121 1. Show all posts

2.19.2012

Number rhombus

Q.  Write a C program to print following number rhombus. 

      1
     121
    12321
   1234321
  123454321
   1234321
    12321
     121
      1


Ans.


/*c program for number rhombus structure*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter number of rows : ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
   for(sp=num-r; sp>=1; sp--)
       printf(" ");
   for(c=1; c<=r; c++)
       printf("%d",c);
   for(c=r-1; c>=1; c--)
       printf("%d",c);
   printf("\n");
 }
 for(r=1; r<=num; r++)
 {
   for(sp=r; sp>=1; sp--)
       printf(" ");
   for(c=1; c<=(num-r); c++)
       printf("%d",c);
   for(c=num-r-1; c>=1; c--)
       printf("%d",c);
   printf("\n");
 }
 getch();
 return 0;
}


/**************************************************
 The output of above program would be:
**************************************************/

Output of of Number rhombus C program
Figure: Screen shot of Number rhombus C program



You might also like to read:

  1. Big list of 98+ C pyramid programs
  2. Latest user asking pyramid programs list