Write a function to multiply two matrices a and b and save t
Write a function to multiply two matrices a and b and save the result in c. The header for the function is
const int N = 3;
void multiplyMatrix(const double a[][N], const double b[][N], double c[][N]);
Program needs to be written in C++. I will reward the the first correct answer! Thanks! :)
prompts user to enter matrix1 & matrix2 then multiplies them together through matrix multiplication.
t mt] [2] ebrat multiply rwo matrices) we 9 nd save the result in a function to multiply two matrices a and 11 12 13 bu 12 bu (ew a21 a22 a23 21 bas en en. a31 a32 33 applied The header of the function is 15% const int N 3. vo Matri const double autN). const double bDEN], double cti DN1); Each element cij is ail x by an x bej an x ba write a test program that prompts the user to enter two 3 x 3 matrices and dis plays their product. Here is a sample run: Enter matrix: 1 2 3 4 5 6 7 8 9 5.2 Fente 0 2 4.5 e multiplication of the matrices is 24 5.3 23.9 1 2 3 0 4.0 11.6 56.3 58.2 1 4.5 2.2 4 5 6 4.3 5.2 17.9 88.7 92.4 89 1.1 1 radian 8.6Solution
#include<iostream.h>
#include<conio.h>
Const int N=3;
Void multiplyMatrix(const double a[][N], const double b[][N], const double c[][N])
{
cout<<\"Multiplying two matrices...\ \";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
sum=0;
for(k=0; k<3; k++)
{
sum = sum + a[i][k] * b[k][j];
}
c[i][j] = sum;// storing the result of the two matrices multiplication into third matrix
}
}
cout<<\"\ Multiplication of two Matrices : \ \";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cout<<c[i][j]<<\" \";
}
cout<<\"\ \";
}
}
void main()
{
clrscr();
int a[3][3], b[3][3], c[3][3], sum=0, i, j, k;
cout<<\"Enter first matrix element (3*3) : \"; //reading first matrix elements
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>mat1[i][j];
}
}
cout<<\"Enter second matrix element (3*3) : \";// reading second matrix elements
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin>>mat2[i][j];
}
}
multiplyMatrix(const a, const b, const c) //multiplication of two matrices
}
output:
Enter first matrix elements(3*3):1
2
3
1
2
3
1
2
3
Enter second matrix elements(3*3):1
2
3
1
2
3
1
2
3
multiplication of two matrices:
6 12 18
6 12 18
6 12 18
![Write a function to multiply two matrices a and b and save the result in c. The header for the function is const int N = 3; void multiplyMatrix(const double a[] Write a function to multiply two matrices a and b and save the result in c. The header for the function is const int N = 3; void multiplyMatrix(const double a[]](/WebImages/42/write-a-function-to-multiply-two-matrices-a-and-b-and-save-t-1131153-1761604310-0.webp)
![Write a function to multiply two matrices a and b and save the result in c. The header for the function is const int N = 3; void multiplyMatrix(const double a[] Write a function to multiply two matrices a and b and save the result in c. The header for the function is const int N = 3; void multiplyMatrix(const double a[]](/WebImages/42/write-a-function-to-multiply-two-matrices-a-and-b-and-save-t-1131153-1761604310-1.webp)
![Write a function to multiply two matrices a and b and save the result in c. The header for the function is const int N = 3; void multiplyMatrix(const double a[] Write a function to multiply two matrices a and b and save the result in c. The header for the function is const int N = 3; void multiplyMatrix(const double a[]](/WebImages/42/write-a-function-to-multiply-two-matrices-a-and-b-and-save-t-1131153-1761604310-2.webp)