Question #29363

My problem is to write C++ code calculate Matrix multiplication i wrote the code but the main problem in changing it into function not in the main and i don't know how !!! could anybody help me please and tell me hint or what's the lesson that should i learn before solving this problem.

That's the code

http://codepad.org/s36rcxls

That's the code

http://codepad.org/s36rcxls

Expert's answer

#include<iostream>

using namespace std;

void compute(){

int l,m,z,n;

int matrixA[10][10];

int matrixB[10][10];

int matrixC[10][10];

cout<<"enter the dimension of the first matrix"<<endl;

cin>>l>>m;

cout<<"enter the dimension of the second matrix"<<endl;

cin>>z>>n;

if(m!=z||z!=m){

cout<<"error in the multiblication enter new dimensions"<<endl;

cout<<"enter the dimension of the first matrix"<<endl;

cin>>l>>m;

cout<<"enter the dimension of the second matrix"<<endl;

cin>>z>>n;

}

else{

cout<<"enter the first matrix"<<endl;

for(int i=0;i<l;i++){

for(int j=0;j<m;j++){

& cin>>matrixA[i][j];

& }

& }

cout<<"enter the second matrix"<<endl;

for(int i=0;i<z;i++){

for(int j=0;j<n;j++){

cin>>matrixB[i][j];

}

}

for(int i=0;i<l;i++){

for(int j=0;j<n;j++){

& matrixC[i][j]=0;

& for(int k=0;k<m;k++){

matrixC[i][j]=matrixC[i][j]+(matrixA[i][k] * matrixB[k][j]);

}

}

}

cout<<"your matrix is"<<endl;

for(int i=0;i<l;i++){

for(int j=0;j<n;j++){

cout<<matrixC[i][j]<<" ";

}

cout<<endl;

}

}

}

int main()

{

compute();

system("pause");

return 0;

}

using namespace std;

void compute(){

int l,m,z,n;

int matrixA[10][10];

int matrixB[10][10];

int matrixC[10][10];

cout<<"enter the dimension of the first matrix"<<endl;

cin>>l>>m;

cout<<"enter the dimension of the second matrix"<<endl;

cin>>z>>n;

if(m!=z||z!=m){

cout<<"error in the multiblication enter new dimensions"<<endl;

cout<<"enter the dimension of the first matrix"<<endl;

cin>>l>>m;

cout<<"enter the dimension of the second matrix"<<endl;

cin>>z>>n;

}

else{

cout<<"enter the first matrix"<<endl;

for(int i=0;i<l;i++){

for(int j=0;j<m;j++){

& cin>>matrixA[i][j];

& }

& }

cout<<"enter the second matrix"<<endl;

for(int i=0;i<z;i++){

for(int j=0;j<n;j++){

cin>>matrixB[i][j];

}

}

for(int i=0;i<l;i++){

for(int j=0;j<n;j++){

& matrixC[i][j]=0;

& for(int k=0;k<m;k++){

matrixC[i][j]=matrixC[i][j]+(matrixA[i][k] * matrixB[k][j]);

}

}

}

cout<<"your matrix is"<<endl;

for(int i=0;i<l;i++){

for(int j=0;j<n;j++){

cout<<matrixC[i][j]<<" ";

}

cout<<endl;

}

}

}

int main()

{

compute();

system("pause");

return 0;

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment