C Program to Multiply two Matrices
top of page

C Program to Multiply two Matrices

Matrix multiplication in C:



#include<stdio.h>

#include<conio.h>

void main()

{

int a[15][15],b[15][15],c[15][15],row, col, i, j, k;

clrscr();

printf("Enter the number of row of Matrix: ");

scanf("%d", &row);

printf("Enter the number of column of Matrix: ");

scanf("%d", &col);

printf("Enter element of first Matrix: \n");

for(i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

scanf("%d",&a[i][j]);

}

}


printf("Enter elements of Second Matrix: \n");

for (i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

scanf("%d",&b[i][j]);

}

}

printf("multiply of the two matrix: \n");

for(i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

c[i][j]=0;

for(k=0;k<col;k++)

{

c[i][j]= c[i][j]+a[i][k]*b[k][j];

}

}

}

for (i=0;i<row;i++)

{

for(j=0;j<col;j++)

{

printf("%d\t",c[i][j]);

}

printf("\n");

}

getch();

}

Output:

Enter the number of row of Matrix: 2

Enter the number of column of Matrix: 2

Enter element of first matrix:

1 1

2 2

Enter elements of Second Matrix:

1 1

2 2

multiply of the two matrix:

3 3

6 6



9 views0 comments
bottom of page