r/C_Programming • u/Red_Bird57 • 4d ago
Question I need help understand what a question is asking me to do in uni exercise
I can't post an image to it, but it says in normal arrays : declare 3 arrays A, B, C all of size 5
The elements of C are the scaler products of A and B (∑︁A[i] × B[i])
And in 2d arrays :
C is there product, (matrix multiplication : C[i][j] = sum of A[i][k] * B[k][j] )
Can someone explain to me what they asking to make
1
Upvotes
2
u/Due-Mortgage-6854 4d ago
Make 3 arrays: A, B, and C.
6
u/gnix0 4d ago
Since others already went straight to the point, I'll just leave a quick advice. On such problems, try to grab a piece of paper and sketch a little bit on it. Draw the matrices, try to get any little visual representation for helping out while you try to understand the problem and eventually move to the solution. Helped me a bunch when I took Linear Algebra, and became a habit I carry to this day!
1
u/ephemere_sloboda 1d ago
The exercise is about loops.
To calculate the scalar product, you need one loop with index i to cycle over the members of A and B.
To calculate matrix product, you need two nested loops (index i and j) to reach every position in the 2d array C, and a third nested loop (k) to swipe the row/column of A and B.