C Programming

C Programming


How To Make Half Rhombus Shape Number Triangle

Posted: 03 Mar 2015 08:57 AM PST

Q. How to make half rhombus number triangle as:

  5
  456
  34567
  2345678
  123456789
  2345678
  34567
  456
  5

Ans.

/*c program for half rhombus number triangle*/
#include<stdio.h>
int main()
{
 int r,c,j,num,n;
 printf("Enter Any Number : ");
 scanf("%d", &num);

 n=num;
 for(r=1; r<=num; r++,n--)
 {
   for(c=n; c<=num; c++)
       printf("%d", c);
   for(c=r, j=num+1; c>1; c--, j++)
       printf("%d", j);
   printf("\n");
 }
 for(r=2; r<=num; r++)
 {
   for(c=r; c<=num; c++)
       printf("%d", c);
   for(c=num-r, j=num+1; c>=1; c--, j++)
       printf("%d", j);
   printf("\n");
 }
 getch();
 return 0;
}

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

Output of How To Make Half Rhombus Shape Number Triangle C program
Figure: Screen shot for How To Make Half Rhombus Shape
Number Triangle C program



You might also like:

  1. Big List of 98+ C Pyramid Programs
  2. Latest Pyramid Programs List Asked By User


Post a Comment