#include<stdio.h>
void main(){
int row1,column1,row2,column2,i,j,k,a[100][100],b[100][100],mul[100][100];
//a[][] for first matrix and b for second matrix b[][]
printf("Enter number of rows of first matrix : ");
scanf("%d",&row1);
printf("Enter number of columns of first matrix : ");
scanf("%d",&column1);
printf("#### Frist Matrix ####
");
for(i=0;i<row1;i++){
for(j=0;j<column1;j++){
printf("Enter element a %d%d : ",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("Enter number of rows of second matrix : ");
scanf("%d",&row2);
printf("Enter number of columns of second matrix : ");
scanf("%d",&column2);
printf("#### Second Matrix ####
");
for(i=0;i<row2;i++){
for(j=0;j<column2;j++){
printf("Enter element a %d%d : ",i+1,j+1);
scanf("%d",&b[i][j]);
}
}
if(column1 == row2){
for(i=0;i<row1;i++){
for(j=0;j<column2;j++){
mul[i][j] = 0;
}
}
for(i=0;i<row1;i++){
for(j=0;j<column2;j++){
for(k=0;k<row2;k++){ //as row2 = column1
mul[i][j] = mul[i][j] + a[i][k] * b[k][j];
}
}
}
for(i=0;i<row1;i++){
for(j=0;j<column2;j++){
printf("%d ",mul[i][j]);
}
printf("
");
}
}
}
double[][] c = new double[N][N];
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
for (int k = 0; k < N; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
enter the number of row=3
enter the number of column=3
enter the first matrix element=
1 1 1
8 8 8
3 3 3
enter the second matrix element=
1 1 1
2 2 2
3 3 3
multiply of the matrix=
6 6 6
12 12 12
18 18 18