How to print Tricky Number Pattern With C programming Laguage

in #howto7 years ago

#include <stdio.h>

int main()
{
int i, j, N;

printf("Enter N: ");
scanf("%d", &N);

//First part of the pattern
for(i=1; i<=N; i++)
{
    //Prints trailing spaces
    for(j=1; j<i; j++)
    {
        printf(" ");
    }

    printf("%d", i);

    //Prints central spacces
    for(j=1; j<=((N - i) * 2 - 1); j++)
    {
        printf(" ");
    }

    //Don't print for last row
    if(i != N)
        printf("%d", i);

    //Moves on to the next row
    printf("\n");
}

//Second part of the pattern
for(i=N-1; i>=1; i--)
{
    //Prints trailing spaces
    for(j=1; j<i; j++)
    {
        printf(" ");
    }

    printf("%d", i);

    //Prints central spaces
    for(j=1; j<=((N - i ) * 2 - 1); j++)
    {
        printf(" ");
    }

    printf("%d", i);

    //Moves on to the next line
    printf("\n");
}

return 0;

}

Coin Marketplace

STEEM 0.15
TRX 0.17
JST 0.028
BTC 68926.89
ETH 2474.86
USDT 1.00
SBD 2.38