by R4R Team

Matrix:
-Multidimensional Array
-Matrix consist of the rows and columns.

Syntax-
array[row][column]
//Martix with numbers of rows and columns

Example-
a[3][2]
//matrix with 3 rows and 2 columns

program-

#include< stdio.h>
int main()
{
int a[10][10],r,c,i,j;
printf("Enter rows and columns\n");
scanf("%d%d",&r,&c);
//input in matrix
printf("Enter %d number in matrix\n",r*c);
for(i=0;i< r;i++)
{
for(j=0;j< c;j++){
scanf("%d",&a[i][j]);
}
}
//Now traverse the matrix
printf("Matrix isn");
for(i=0;i< r;i++)
{
for(j=0;j< c;j++){
printf("%d ",a[i][j]);
}
printf("\n");
}
}


output-

Enter rows and columns
2 2
Enter 4 number in matrix
1 2 3 4
Matrix is
1 2
3 4

Enter rows and columns
3 3
Enter 9 number in matrix
1 2 3 4 5 6 7 8 9
Matrix is
1 2 3
4 5 6
7 8 9

-In this program, firstly we take a input of the numbers of rows and columns of matrix, then input in matrix.
-As matrix is two dimensional array so we require 2 loops for input in matrix.
-First loop are for rows insertion and second loop are for column insertion.




Leave a Comment: