Click the Follow Button

C; How to print pattern using 2D array.

program:

#include<stdio.h>

int main ()
{
    int i, j;
    int a [5][5] =
    {
        {1, 0, 0, 0, 0},
        {1, 1, 0, 0, 0},
        {1, 1, 1, 0, 0},
        {1, 1, 1, 1, 0},
        {1, 1, 1, 1, 1},
    };

    for (i = 0; i < 5; i++)
    {
        for(j = 0; j < 5; j++)
        {
            if (a[i][j] == 1)
            {
            printf("*  ");
            }

            if (a[i][j] == 0)
            printf(" ");
        }
        printf("\n");
    }

    return 0;
}


Output;

*      
*  *
*  *  *
*  *  *  *
*  *  *  *  *

Comments

Popular Posts

TIC - TAC - TOE

Prime and not prime number

do_while loop is to do something again and again