Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # include <iostream>
- # include <stdlib.h>
- using namespace std;
- void readArr(int, int, float**);
- void multArrs(int, float **, int, float **, float **);
- void printArr(int,int, float[3][3]);
- int main(int argc, char *argv[])
- {
- int r1, c1, r2, c2;
- float **Mat_1, **Mat_2, **Mat_Res;
- r1 = atoi(argv[1]);
- c1 = atoi(argv[2]);
- r2 = atoi(argv[3]);
- c2 = atoi(argv[4]);
- if (c1 == r2)
- {
- cout<<endl<<"\tM A T R I X 1"<<endl<<endl;
- readArr(r1,c1,Mat_1);
- cout<<endl<<"\tYou wrote:"<<endl<<endl;
- printArr(c1,r1,Mat_1);
- cout<<endl<<"\tYou wrote:"<<endl<<endl;
- printArr(c2,r2,Mat_2);
- cout<<endl<<"\tM A T R I X 2"<<endl<<endl;
- readArr(r2,c2,Mat_2);
- multArrs(r1,Mat_1,c2,Mat_2,Mat_Res);
- printArr(c1,r2,Mat_Res);
- }
- else
- {
- cerr<<"Invalid parameters."<<endl;
- exit(0);
- }
- return 0;
- }
- void readArr(int r, int c, float** Mat)
- {
- int i,j;
- i = 0;
- j = 0;
- Mat =(float**)calloc(r,sizeof(float*));
- for(i=0;i<r;i++)
- *(Mat+i)=(float*)calloc(c,sizeof(float));
- for (i=0;i<r;i++)
- {
- for (j=0;j<c;j++)
- {
- cout<<"\tValue for Matrix ["<<i<<"]["<<j<<"]: ";
- cin>>Mat[i][j];
- }
- }
- }
- void multArrs(int r1, float** Mat_1, int c2, float** Mat_2, float** Mat_res)
- {
- int i,j,k,res;
- Mat_res =(float**)calloc(r1,sizeof(float*));
- for(i=0;i<r1;i++)
- *(Mat_res+i)=(float*)calloc(c2,sizeof(float));
- for (i=0;i<r1;i++)
- {
- for (j=0;j<c2;j++)
- {
- for(k=0; k<r1; k++)
- res += Mat_1[i][k]*Mat_2[k][j];
- }
- }
- }
- void printArr(int c,int r, float Mat[3][3])
- {
- int i,j;
- for (i=0;i<c;i++)
- {
- cout<<"\t|";
- for (j=0;j<r;j++)
- cout<<Mat[i][j];
- cout<<'|'<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement