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

19 comments:

  1. 1
    1 2
    1 2 3
    1 2 3 4
    1 2 3
    1 2
    1

    ReplyDelete
    Replies
    1. Your above program source code at:

      http://cprogrammingcodes.blogspot.in/2012/07/number-triangle_28.html

      Delete
  2. A B C D E F E D C B A
    A B C D E E D C B A
    A B C D D C B A
    A B C C B A
    A B B A
    A A

    ReplyDelete
    Replies
    1. Your above character pyramid programs source code:

      http://www.cprogrammingcodes.blogspot.in/2012/09/character-pyramid.html

      Delete
  3. what does sp means?

    ReplyDelete
    Replies
    1. sp represent space.
      It is easily to remember that what is the working of specific variable.

      Delete
  4. Hey there, i saw this rhombus program and it is working great, i was wondering if you could give the explanation of the source code in comments? If you have time ofc. thx

    ReplyDelete
  5. 1
    121
    12321
    1234321

    please send me this codeing

    ReplyDelete
    Replies
    1. @Ashish,

      Your required Vertical Continues Number Pyramid C program at :

      http://cprogrammingcodes.blogspot.in/2013/08/number-triangle-design_23.html

      Delete
  6. Replies
    1. @sri surya,

      Your required Vertical Continues Number Pyramid C program at :

      http://cprogrammingcodes.blogspot.in/2013/08/vertical-continues-number-pyramid.html

      Delete
  7. program for this

    0
    1 0 1
    2 1 0 1 2
    3 2 1 0 1 2 3
    4 3 2 1 0 1 2 3 4
    5 4 3 2 1 0 1 2 3 4 5
    4 3 2 1 0 1 2 3 4
    3 2 1 0 1 2 3
    2 1 0 1 2
    1 0 1
    0

    ReplyDelete
    Replies
    1. //fb/sheoran.dinesh
      #include
      #include
      void main()
      {
      int i,j,k,l,m,n;
      clrscr();

      for(i=0;i<=5;i++)
      {

      for(j=i;j>=0;j--)
      {
      printf("%d",j);

      }
      for(k=1;k<=i;k++)
      {
      printf("%d",k);
      }

      printf("\n");
      }
      //printf("\n\n");
      for(l=4;l>=0;l--)
      {
      for(m=l;m>=0;m--)
      {
      printf("%d",m);
      }
      for(n=1;n<=l;n++)
      {
      printf("%d",n);
      }
      printf("\n");
      }
      getch();
      }

      Delete
  8. how to make this programme in two veriable ???
    for ex.:
    int i,j;

    ReplyDelete
    Replies
    1. @Harsh Makawana,

      You can make above number rhombus C program using only 2 integer variable,
      as you can input the int num value already before the compile of program and each loop int value has own life and scope so just uses inner loop same int variable.

      Hope its help you.

      Delete
  9. how about the inputted number is the side of the rhombus??? send me pls..

    ReplyDelete
  10. i want this program .
    1 1
    1 2 2 1
    1 2 3 3 2 1
    1 2 2 1
    1 1

    ReplyDelete
  11. if the value of n is 4 the output shoild be in the form of 1234321.
    and should use only one for foor or while loof.

    hint:can use if loop inside for loop.

    ReplyDelete
  12. 1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1
    2 3 4 5 4 3 2
    3 4 5 4 3
    4 5 4
    5
    Please help me for this...

    ReplyDelete