Hi, I am trying to write a function which multiplies two 2d arrays and it stores a result in a third 2d array. Now I want to multiply this result with another 2d array.

I have tried to write a function which does this multiplication and returns a pointer. but I can not do multiplication second time. Can anyone help me plz. Thank you.

I am posting my code here:

Code://matrix multiplication #include<iostream> #include<cmath> using namespace std; double** matmulti(int rows1,int columns1,double dynarray1[][3],int rows2,int columns2,double dynarray2[][3]); int main() { int rowsx=3; int columnsx=3; int rowsy=3; int columnsy=3; double alpha=1.2;float beta=2.3;float gamma=1.4; double x,y,z; double rotx[3][3]={{1.00,0,0}, {0,cos(alpha),-sin(alpha)}, {0,sin(alpha),cos(alpha)} } ; double roty[3][3]={{cos(beta),0,sin(beta)}, {0,1.00,0}, {-sin(beta),0,cos(beta)} }; double rotz[3][3]={{cos(gamma),-sin(gamma),0}, {sin(gamma),cos(gamma),0}, {0,0,1.00} }; double** result=matmulti(rowsx,columnsx,rotx,rowsy,columnsy,roty); //now I want to multiply this result with the third matrix which I can not do double** result1=matmulti(rowsx,columnsx,result,rowsy,columnsy,rotz); } double** matmulti(int rows1,int columns1,double dynarray1[][3],int rows2,int columns2,double dynarray2[][3]) { int rows=rows1; int columns=columns2; double** result; result=new double* [rows]; for(int i=0;i<rows;i++) { result[i]=new double[columns]; } //cout<<"\n\n\nresult is \n\n"; if(columns1==rows2){ for(int i=0;i<rows1;i++){ for(int j=0;j<columns2;j++){ for(int k=0;k<rows2;k++){ result[i][j]+=(dynarray1[i][k])*(dynarray2[k][j]); } //cout<<result[i][j]<<" "; } //cout<<"\n"; } }else { cout<<"Matrices can not be multiplied\n"; exit(-1); } return result; for(int i=0;i<3;i++) { delete[] result[i]; } delete result; }