Think about it. Your multiply routine has 3 loops with 3 index variables (i, d and k) that each go from 0 to a certain limit (c, m and c) respectively. You fill your product matrix using product[i][d], so you have
product[0][0]...product[0][m-1]
...
product[c-1][0]...product[c-1][m-1]
That means that your for loop for printing the product matrix should be
The way you currently have it, d stops at k, which (from your multiply loop) remains equal to c. Thus, you are printing c rows and c columns, hence it only working for a square matrix.Code:for i from 0 to c
for d from 0 to m
EDIT: And this should be a huge, huge clue to just how awful one-letter variable names are. They are only useful for loop indexes, (x,y) coordinates and very simple math equations. Variable names like matrix1_rows, matrix2_cols, product_rows, product_cols would make this much, much clearer, and keep you from making such mistakes. You have been warned...never post such ridiculous stuff here again, or face utter humiliation :p.