Saturday, 11 June 2016

Number pattern 2




Firstly we will take a for loop(outer) for no of rows.

Print spaces
For every ith row , print n-i spaces.

Print numbers
For every ith row print numbers.Initialize no = 1.After printing a number,increment no.


#include<stdio.h>

int main()
{
    int i,j,n,no=1;

    printf("Enter number of rows ");
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
        for(j=i;j<n;j++)
             printf(" ");

        for(j=1;j<=i;j++)
             printf("%d ",no++);

        printf("\n");
    }   

    return 0;
}

No comments:

Post a Comment