Loading...

Rhombus Pattern

Programme:

#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;
}

Output:

Enter maximum number : 5
    1 1
   2   2
  3     3
 4       4
5         5
 4       4
  3     3
   2   2
    1 1