Two dimensional array

Syntax: data-type    array-name[row][column];

Example:

float mat[3][4];

The memory space can be imagined as follows:

mat[0][0]
mat[0][1]
mat[0][2]
mat[0][3]
mat[1][0]
mat[1][1]
mat[1][2]
mat[1][3]
mat[2][0]
mat[2][1]
mat[2][2]
mat[2][3]

Code example: Write a c program to input a 3×3 matrix And show the matrix.

#include<stdio.h>
int main()
{
     int mat[3][3],i,j;
     printf("Enter element of 3X3 matrix:\n");
     for(i=0;i<3;i++)
     {
          for(j=0;j<3;j++)
          {
             scanf("%d",&mat[i][j]);
          }
     }
     printf("The given matrix is : \n");
     for(i=0;i<3;i++)
     {
          for(j=0;j<3;j++)
          {
             printf("%d",mat[i][j]);
          }
     }
     return 0;
}

OUTPUT

Enter element of 3X3 matrix:
1 2 4
5 6 3
7 9 8
The given matrix is :
1 2 4
5 6 3
7 9 8


Next Previous