C program that multiplies the matrix a by the matrix b and stores the result in the matrix c
###### Posted by Samath
Last Updated: May 04, 2016

Consider the following variable declarations. Assume each variable stores the values in a matrix. Write code that multiplies the matrix a by the matrix b and stores the result in the matrix c .
float a[2][3],b[3][2],c[2][2];

Solution:

#include<stdio.h>
int main(int argc, char *argv[])
{
float a[2][3], b[3][2], c[2][2];
int i, j;
float value,temp1=0,temp2=0;
printf("Enter Matrix 1\n");
for (i = 0; i < 2; i++){
printf("Enter Elements of Row %d \n", i + 1);
for (j = 0; j < 3; j++){
printf("Enter value of Column %d ", j + 1);
scanf("%f", &value);
a[i][j] = value;
}
}
printf("Enter Matrix 2\n");
for (i = 0; i < 3; i++){
printf("Enter Elements of Row %d \n", i + 1);
for (j = 0; j < 2; j++){
printf("Enter value of Column %d ", j + 1);
scanf("%f", &value);
b[i][j] = value;
}
}
for (i = 0; i < 2; i++){
for (j = 0; j < 3; j++){
temp1 = temp1 + a[i][j] * b[j][i];
temp2 = temp2 + a[i][j] * b[j][1];
}
c[i][0] = temp1;
c[i][1] = temp2;
temp1 = 0;
temp2 = 0;
}
for (i = 0; i < 2; i++){
for (j = 0; j < 2; j++)
printf("%.2f	", c[i][j]);
printf("\n");
}

return 0;
}

###### C Program to Check whether entered matrix is magic square or not
Samath | Jan 03, 2017
###### Write a C program to Print Square of Each Element of 2D Array Matrix
Samath | Jan 04, 2017
###### C++ program that adds, subtracts, multiplies, or divides two integers
Samath | Nov 04, 2014
###### C program that receives a positive float number and divides it by two until the result is less than or equal to zero
Samath | Jun 12, 2015