Docsity

Matrix Multiplication C Program, Study notes of Computer science

Toggle sidebar
bg1
//MULTIPLICATION OF MATRIX
#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");
}
}
pf2

Partial preview of the text

Download Matrix Multiplication C Program and more Study notes Computer science in PDF only on Docsity!

//MULTIPLICATION OF MATRIX

#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;

}