# Answer to Question #29363 in C++ for abdelrahman mostafa

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
1
2013-05-09T08:25:43-0400
#include<iostream>

using namespace std;

void compute(){

int l,m,z,n;
int matrixA;
int matrixB;
int matrixC;

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]);
}
}
}

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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!