# Matrix multiplication!!

This is a discussion on Matrix multiplication!! within the C++ Programming forums, part of the General Programming Boards category; I have created a class of 3*3 matrix. In which i have defined an operator for matrix multiplication. the code ...

1. ## Matrix multiplication!!

I have created a class of 3*3 matrix. In which i have defined an operator for matrix multiplication.

the code goes like this:
Code:
```matrix operator * (matrix m)
{
matrix x;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
x.array[i][j]=array[1][j] * m.array[i][1];
x.array[i][j]=array[2][j] * m.array[i][2];
x.array[i][j]=array[3][j] * m.array[i][3];

return x;
}```

can anybuddy help me this code is wrong

2. Easy start: If you intend all of those statements to be inside a loop, you will need braces.

You seem to have looked up matrix multiplication, but you forgot about the additions.

3. Here's a hint:
result[i][j] += array [i][k] * array[k][j]

4. Here's another important hint: Arrays start at zero. An array with three elements has valid indexes [0], [1], and [2]. You got the loops right, bt not your hard-coded indexes.

5. Check your curly brackets, your code isn't doing what you think it is doing.

You need to put brackets after the second for statement

Popular pages Recent additions