Program C Two Dimensional Array

To initialize and print two dimensional array in C programming, you have to ask to the user to enter the row and columns size of the array for the array dimension, then ask to enter the array elements of entered dimension. To print back all the array element in two dimension (row by column), you have to use two for loops, the first one is outer for loop and the second one is inner for loop. Outer for loop is responsible for rows and the inner for loop is responsible for columns.

#include<stdio.h>
#include<conio.h>
void main()
{
    clrscr();
    int array[10][10], row, column, i, j;
    printf("Enter number of row for Array (max 10) : ");
    scanf("%d",&row);
    printf("Enter number of column for Array (max 10) : ");
    scanf("%d",&column);
    printf("Now Enter %d*%d Array Elements : ",row, column);
    for(i=0; i<row; i++)
    {
        for(j=0; j<column; j++)
        {
            scanf("%d",&array[i][j]);
        }
    }
    printf("The Array is :\n");
    for(i=0; i<row; i++)
    {
        for(j=0; j<column; j++)
        {
            printf("%d  ",array[i][j]);
        }
        printf("\n");
    }
    getch();
}


Run:

Run2:

 

No comments:

Post a Comment

100 C Programs with Code and Output

Program 1: C Program To Read Two Numbers And Print The Sum Of Given Two Numbers. Program 2: C Program To Read Three Numbers And Prin...