Matrix Product

Apr 14, 2013 at 9:43pm
Here is my code so far, but I dont know what to do now. I am trying to write a function that takes 3 10x10 arrays as arguments and then stores the matrix product of the first two arguments in the 3rd argument. Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cmath>

using namespace std;

int main(){
        int i, j, x;
        int a[10][10], b[10][10], c[10][10];
        for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
        for(int x = 0; x < 10; x++){
        c[i][j] += a[i][x] * b[x][j];
}}}

        cout << c[i][j];


return 0;
}
Last edited on Apr 14, 2013 at 9:57pm
Apr 14, 2013 at 9:47pm
Use code tags:
http://www.cplusplus.com/articles/jEywvCM9/

You should always tell what type of problems you are facing. (compile error or runtime error). Tell what you expected and what you got instead.

You haven't initialized c[i][j] to 0 before adding a[i][x] * b[x][j] to it.
Last edited on Apr 14, 2013 at 9:49pm
Topic archived. No new replies allowed.