Good Programs in C
Good Programs in C
if(colsa!=rowsb) {
printf("The number of columns in A and rows in B dont match");
getch();
return ;
}
//initialising the final Matrix C of the order rowsa X colsb
for(row=0;row<rowsa;row++)
for(col=0;col<colsb;col++)
c[row][col]=0;
//input elements of Matrix A
for(row=0;row<rowsa;row++)
for(col=0;col<colsa;col++) {
printf("Enter the element on %d row and %d col of Matrix A: ",row+1,col+1);
scanf("%d",&a[row][col]);
}
//input elements of Matrix B
for(row=0;row<rowsb;row++)
for(col=0;col<colsb;col++) {
printf("Enter the element on %d row and %d col of Matrix B: ",row+1,col+1);
scanf("%d",&b[row][col]);
}
//the final Matrix C is of the order rowsa X colsB
for(k=0;k<colsb;k++)
for(row=0;row<rowsa;row++)
for(col=0;col<colsa;col++)
//Starting with the first row of Matrix A , element at each ith column of Matrix A is multiplied
//by the element at the corresponding ith row of Matrix B
//This step is repeated for the other remaining rows of Matrix A
//ie each row of Matrix A makes a row in final Matrix C
//ie each column of Matrix B makes a column in final Matrix C
c[row][k]= c[row][k]+a[row][col]*b[col][k];
%d\n",row+1,col+1,c[row][col]);