a. Given one 2-dimensional array (5X3) and one 1-dimensional array(3X1), calcula
ID: 3615461 • Letter: A
Question
a. Given one 2-dimensional array (5X3) and one 1-dimensional array(3X1), calculate a third array (5X1) using:
Cij =sum(Aik*Bkj) This is matrixmultiplication. Written out long hand, it looks like this(I’m not using C++ array locations here – Ididn’t start with zero, I started with1).
C11 =A11*B11 + A12*B21 +A13*B31 Array C is thenew array.
C21 =A21*B11 + A22*B21 + A23*B31 Array Ais the (5X3) array.
C31 =A31*B11 + A32*B21 + A33*B31 Array Bis the (3X1) array.
C41 =A41*B11 + A42*B21 + A43*B31
C51 =A51*B11 + A52*B21 + A53*B31
Test your programby filling the two dimensional array, row by row using loops, withthe even numbers 2 through 30. Fill the one dimensional arraywith the numbers 1, 2, and 3. You can hard code these valuesinto your program rather than use user input. Output eacharray as it looks (ie. The 5X3 array should be printed as a 5X3,etc.)
//my code
#include<iostream>
using namespace std;
#include<math.h>
int main()
{
//definevaribles
intbiggest[5][3],bigger[5], big[3], row, col, i, j, k;
i=2;
j=1;
//math and looping
for (row=0;row<=4;row++)
{for(col=0;col<=2;col++)
{biggest[row][col]=i;
i=i+2;
cout<<" "<<biggest[row][col]<<"";
}
cout<<" ";
}
for (row=0;row<=2;row++)
{bigger[row]=j;
j=j+1;
cout<<" "<<bigger[row]<<"";
cout<<" ";
}
system("pause");
}
Explanation / Answer
please rate - thanks not quite right #include #include void input(int[][3],int,int); void multiplyMatrix(int[][3], int[][1],int[][1],int,int); using namespace std; int main() { int n=3,m=5,i,j; int a[5][3],b[3][1]={1,2,3},c[5][1]; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.