Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main()
- {
- int i,j;
- ofstream fout("fout.txt");
- const int n1=2;
- const int m1=2;
- const int n2=2;
- const int m2=2;
- int a[n1][m1];
- fout<<"size A="<<n1<<'*'<<m1<<endl;
- for (i=0;i<n1;i++)
- {
- for (j=0;j<m1;j++)
- a[i][j]=rand()%10;
- }
- for (i=0;i<n1;i++)
- {
- for (j=0;j<m1;j++)
- fout<<a[i][j]<<' ';
- fout<<endl;
- }
- fout<<endl;
- int b[n2][m2];
- fout<<"size B="<<n2<<'*'<<m2<<endl;
- for (i=0;i<n2;i++)
- {
- for (j=0;j<m2;j++)
- b[i][j]=rand()%10;
- }
- for (i=0;i<n2;i++)
- {
- for (j=0;j<m2;j++)
- fout<<b[i][j]<<' ';
- fout<<endl;
- }
- fout.close();
- ifstream fin("fout.txt");
- for (i=0;i<n1;i++)
- {
- for (j=0;j<m1;j++)
- fin>>a[i][j];
- }
- for (i=0;i<n2;i++)
- {
- for (j=0;j<m2;j++)
- fin>>b[i][j];
- }
- int c[n1][n2];
- if (n1==n2&&m1==m2)
- {
- for (i=0;i<n2;i++)
- {
- for (j=0;j<m2;j++)
- c[i][j]=a[i][j]+b[i][j];
- }
- for (i=0;i<n2;i++)
- {
- for (j=0;j<m2;j++)
- cout<<c[i][j]<<' ';
- cout<<endl;
- }
- }
- else {
- cout<<"can not be folded";
- cout<<endl;
- }
- int d[n1][n2],p,s;
- s=0;
- if (n1==m2)
- {
- for (i=0;i<n1;i++)
- {
- for (j=0;j<m2;j++)
- {
- d[i][j]=0;
- for (int k=0;k<n1;k++)
- d[i][j]+=a[i][k]*b[k][j];
- }
- }
- for (i=0;i<n2;i++)
- {
- for (j=0;j<m2;j++)
- cout<<d[i][j]<<' ';
- cout<<endl;
- }
- }
- else cout<<"can not be multiplied";
- fin.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment