You are using a version without Ads of this website. Please, consider donating:

### Matrices (NxM) Multiplication

Hello everyone, I would need to write a c++ program that takes a matrix from the console, trasposes it, and then calculates the product of the two. I managed to write the first part of the code with the trasposed one. I would need an help for the last part insted. When I run the program it gives back random numbers, I don't know where I am mistaking. This is the source code I wrote.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677`` ``````#include using namespace std; const int N=2, M=3; void getMatrix(int matrix[N][M]); void printMatrix(int matrix[N][M]); void calculateTrasposed(int m[N][M], int t[M][N]); void calculateProduct(int m1[N][M],int m2[M][N], int product[N][N]); int main(){ int matrix[N][M], trasposed[M][N], product[N][N]; getMatrix(matrix); printMatrix(matrix); calculateTrasposed(matrix,trasposed); calculateProduct(matrix,trasposed,product); system("PAUSE"); } void getMatrix(int matrix[N][M]){ cout << "Insert the " << N << " x " << M << " matrix: " <> matrix[i][j]; return; } void printMatrix(int matrix[N][M]){ cout << "The inserted matrix is: " <

Thank you.

P.S. sorry for the english, I'm italian.

Last edited on
Hi!
I'm a beginner C++ programmer too from the neighbourhood (HUngary) :)

First of all: Trasposed - missing n --correct--> Transposed

Transpose of a matrix:
http://en.wikipedia.org/wiki/Transpose

I have corrected your code, you can test production of matrices online e.g. here:

Checking the matrix product:
http://easycalculation.com/matrix/matrix-multiplication.php

As I said I am beginner so I can make mistakes
but it looks like my code works:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475`` ``````#include using namespace std; const int N=2, M=3; void getMatrix(int matrix[N][M]); void printMatrix(int matrix[N][M]); void calculateTransposed(int m[N][M], int t[M][N]); void calculateProduct(int m1[N][M],int m2[M][N], int product[N][N]); int main(){ int matrix[N][M], Transposed[M][N], product[N][N]; getMatrix(matrix); printMatrix(matrix); calculateTransposed(matrix,Transposed); calculateProduct(matrix,Transposed,product); //system("PAUSE"); } void getMatrix(int matrix[N][M]){ cout << "Insert the " << N << " x " << M << " matrix: " <> matrix[i][j]; return; } void printMatrix(int matrix[N][M]){ cout << "The inserted matrix is: " <
hahahahaah nice one for the TRANSPOSED ;)!
Thank you, now I understood, it's working perfectly.
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: