+ 4

why is this code not working? im trying A*B=C

https://code.sololearn.com/cHv0cU8toAL6/?ref=app

22nd Aug 2018, 6:08 PM
Țucu🇷🇴
Țucu🇷🇴 - avatar
6 Réponses
+ 8
Your matrixes are 10x10 but when you initialize them your are iterating only up to 3 lines and 3 columns. Try to change their sizes to 3x3 or iterate over all 10 lines and 10 columns.
22nd Aug 2018, 6:17 PM
Eduardo Petry
Eduardo Petry - avatar
+ 9
Țucudean Adrian-Ionuț The only thing I can think of is the numbers in matrix `c` are overflowing after you do the product. Try finding a way to limitate the range in which you are generating the numbers in matrixes `a` and `b`. 👍🏻 Edit: actually no... I'll check it more carefully after I get home. Edit2: I really don't know why it's not working properly... I'll leave this for your reference: https://www.sanfoundry.com/cpp-program-perform-matrix-multiplication/
22nd Aug 2018, 6:52 PM
Eduardo Petry
Eduardo Petry - avatar
+ 8
Țucudean Adrian-Ionuț You are using i, j and k to iterate over `c`... that's because you are doing the matrix product. Try printing matrix `c` in another loop after doing the product, using only i and j as in: for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << c[i][j] << "|"; } cout << endl; } In other words, separate product calculation process from the printing process... (sorry if this got a bit confusing)
22nd Aug 2018, 6:27 PM
Eduardo Petry
Eduardo Petry - avatar
+ 4
still not working
22nd Aug 2018, 6:26 PM
Țucu🇷🇴
Țucu🇷🇴 - avatar
+ 4
lool those 3 (for) are confuzing i cant follow with mi mind the entire code
22nd Aug 2018, 7:00 PM
Țucu🇷🇴
Țucu🇷🇴 - avatar
+ 3
look at this, now is working fine but the results are still false (this code is giving me an headache)
22nd Aug 2018, 6:47 PM
Țucu🇷🇴
Țucu🇷🇴 - avatar