+ 2
Multiply two matrices dimension 3 by 3
This code gives 'compilation error', but I don't know why đ Have you any clue? https://code.sololearn.com/cQ1npEZb3soi/?ref=app
3 Answers
+ 4
1.
There are stray characters everywhere, which seem to be invisible on my phone but they are visible on pc, they look like purple dots.
2.
void main has to be int main, no ifs or buts
3.
void matrix_mult( int[][3] mat1, int[][3] mat2), the brackets go after the name, thus:
void matrix_mult( int mat1[][3], int mat2[][3])
4.
int mat3[][3]; is invalid, the size of the 2d array is not known.
This is different from the function because there it decays into a pointer to the beginning of the array
so it should be:
int mat3[3][3]; for a 3x3
The same applies to the mat1 and mat2 inside the main function
5.
The i's and j's inside the for loops are not defined
For example:
for ( i = 0 ; i <= 2 ; i++ )
should be
for (int i = 0 ; i <= 2 ; i++ )
Also don't define them outside the loop if you're only using them inside the loop like:
int i;
for ( i = 0 ; i <= 2 ; i++ )
That just becomes a mess.
6.
line 49:
mat2[i][j] = ;
Should give it a value ^^.
7. Just a tip
Use {} after the for loops, sometimes you use them and sometimes you don't.
While it is true that you don't need them when you're only using 1 statement inside the loop, you can run into bugs if you decide that you have to put more inside it later on and forget to add the {}
for ( j = 0 ; j <= 2 ; j++ )
// cin>>mat2[i][j] ;
mat2[i][j] = ;
is just an accident waiting to happen.
That seems to be the most of it, have fun :)
+ 7
Dennis is 100% correct.
Not sure what you can do about the invisible dots. I too could not see them until I fired up the pc. Strange.
+ 1
thanks @dennis
I fix some of your advices
I will check the stange chars đ