

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This c program demonstrates the implementation of matrix multiplication. The user is prompted to input the orders and elements of two matrices to check if they can be multiplied. If the number of columns of the first matrix is equal to the number of rows of the second matrix, the program performs the multiplication and displays the resulting matrix.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include <stdio.h> #include<math.h>
int main() { int a[3][3],b[3][3],r1,c1,r2,c2,i,j,k,mul[3][3]; printf("Input order of first matrix\n"); scanf("%d\n%d",&r1,&c1); printf("Input order of second matrix\n"); scanf("%d\n%d",&r2,&c2); printf("Input elements of first matrix\n"); for(i=0;i<r1;i++){ for(j=0;j<c1;j++){ scanf("%d",&a[i][j]); } } printf("Input element of second matrix\n"); for(i=0;i<r2;i++){ for(j=0;j<c2;j++){ scanf("%d",&b[i][j]); } }
if(c1!=r1){ printf("Multiplication is not possible"); } else{ printf("multiply of the matrix=\n"); for(i=0;i<r1;i++){ for(j=0;j<c2;j++){ mul[i][j]=0; for(k=0;k<c1;k++){ mul[i][j]+=a[i][k]*b[k][j]; } } } for(i=0;i<r1;i++){ for(j=0;j<c2;j++){ printf("%d\t",mul[i][j]); } printf("\n"); } }
return 0;
}