Saturday, August 16, 2014

How To Design A Number Rhombus Pattern C Program

Q. Write a C program to print the following number rhombus pattern design as:

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

Ans.


/*c program for how to design a number rhombus pattern*/
#include<stdio.h>
int main()
{
 int num,r,c,sp,n;

 printf("Enter maximum number : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
   for(sp=num-r; sp>=1; sp--)
      printf(" ");
   printf("%d", r);
   for(sp=r*2; sp>1; sp--)
      printf(" ");
   printf("%d", r);
   printf("\n");
 }
 for(r=1,n=num-1; r<num; r++,n--)
 {
   for(sp=r; sp>=1; sp--)
      printf(" ");
   printf("%d",n);
   for(sp=n*2; sp>1; sp--)
      printf(" ");
   printf("%d", n);
   printf("\n");
 }
 getch();
 return 0;
}

/*************************************************************
The output of above number rhombus program:
*************************************************************/
Output of How To Design A Number Rhombus Pattern  C Program
Figure: Screenshot for How To Design A Number Rhombus Pattern
 C Program

No comments:

Post a Comment