Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication4.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- int m1,n1,m2,n2;
- ifstream fin("TextFile1.txt");
- fin>>n1>>m1;
- system("pause");
- double **a=new double*[n1];
- for(int i=0;i<n1;i++)
- a[i]=new double[m1];
- for(int i=0;i<n1;i++)
- for(int j=0;j<m1;j++)
- fin>>a[i][j];
- fin>>n2>>m2;
- double **b=new double* [n2];
- for(int i=0;i<n2;i++)
- b[i]=new double[m2];
- for(int i=0;i<n2;i++)
- for(int j=0;j<m2;j++)
- fin>>b[i][j];
- fin.close();
- cout<<"A+B:"<<endl;
- if (n1==n2 && m1==m2)
- {
- double **sum=new double* [n1];
- for(int i=0;i<n1;i++)
- sum[i]=new double[m1];
- for(int i=0;i<n1;i++)
- {for(int j=0;j<m1;j++)
- {sum[i][j]=a[i][j]+b[i][j];
- cout<<sum[i][j]<<" ";}
- cout<<endl;}
- }
- else cout<<"error";
- cout<<"A*B:"<<endl;
- if(m1==n2)
- {double **pr=new double* [n1];
- for(int i=0;i<n1;i++)
- pr[i]=new double[m2];
- for(int i=0;i<n1;i++)
- for(int j=0;j<m1;j++)
- pr[i][j]=0;
- for(int i=0;i<n1;i++)
- { for(int j=0;j<m2;j++)
- {for(int k=0;k<m1;k++)
- pr[i][j]+=a[i][k]*b[k][j];
- cout<<pr[i][j]<<" ";}
- cout<<endl;}
- }
- else cout<<"error";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement