top of page
Writer's pictureRajesh Singh

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

Recent Posts

See All

Files MCQ in Python

File Processing MCQ Q1. Which function writes a list of lines in File? A.      Writelines() B.      Write() C.      Tell() D.      All of...

Python List MCQ Questions

Q1. What is output of below python code? dict= {1:'1', 2:'2', 3:'3'} del dict[1] dict[1] = '10' del dict[2] print (len(dict)) A. 1 B. 2...

コメント


bottom of page