Thursday 9 May 2013

Pyramid-3



DESCRIPTION: This program prints the pyramid as below-
                                                                 1
                                                               121
                                                             12321
                                                           1234321


PROGRAM:


#include<stdio.h>
main()
{
    int i,j,k,n,m;
    printf("enter no. of lines\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        for(m=0;m<n-i;m++)
        printf(" ");
        for(j=0,k=i;j<=i||k!=0;j++)
        {
            if(j<=i)
            printf("%d",j+1);
            else if(k!=0)
            {
            printf("%d",k--);
            }
        }
        printf("\n");
    }
}



OUTPUT WINDOW:



No comments:

Post a Comment