Wednesday, May 4, 2011

Number Diamond/Brick

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,i,j;
    clrscr();
    printf("enter a no.<=11 for generating the patter\n");
    scanf("%d",&n);
    printf("desired pattern is\n");

    for(i=1;i<=n;i++)
    {
        printf("\t");
       
        for(j=1;j<=n-i;j++)          //for blanks space
        printf("   ");

        for(j=n;j>=n+1-i;j--)        //for left upper half
        printf("%3d",j);

        for(j=n+2-i;j<=n;j++)        //for right upper half
        printf("%3d",j);

        printf("\n");
    }

    for(i=1;i<=n;i++)
    {
        printf("\t");
        
        for(j=1;j<=i;j++)             //for blanks space
        printf("   ");

        for(j=n;j>=i+1;j--)           //for left lower half
        printf("%3d",j);

        for(j=i+2;j<=n;j++)           //for right lower half
        printf("%3d",j);

        printf("\n");
    }
    getch();
}
 
output 


No comments: