Advertisement
EnikeevaLada

Untitled

Nov 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // ConsoleApplication4.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. using namespace std;
  8. int _tmain(int argc, _TCHAR* argv[])
  9. {
  10. int m1,n1,m2,n2;
  11. ifstream fin("TextFile1.txt");
  12. fin>>n1>>m1;
  13. system("pause");
  14. double **a=new double*[n1];
  15. for(int i=0;i<n1;i++)
  16. a[i]=new double[m1];
  17.  
  18. for(int i=0;i<n1;i++)
  19. for(int j=0;j<m1;j++)
  20. fin>>a[i][j];
  21. fin>>n2>>m2;
  22. double **b=new double* [n2];
  23. for(int i=0;i<n2;i++)
  24. b[i]=new double[m2];
  25. for(int i=0;i<n2;i++)
  26. for(int j=0;j<m2;j++)
  27. fin>>b[i][j];
  28. fin.close();
  29. cout<<"A+B:"<<endl;
  30. if (n1==n2 && m1==m2)
  31. {
  32. double **sum=new double* [n1];
  33. for(int i=0;i<n1;i++)
  34. sum[i]=new double[m1];
  35. for(int i=0;i<n1;i++)
  36. {for(int j=0;j<m1;j++)
  37. {sum[i][j]=a[i][j]+b[i][j];
  38. cout<<sum[i][j]<<" ";}
  39. cout<<endl;}
  40. }
  41. else cout<<"error";
  42. cout<<"A*B:"<<endl;
  43. if(m1==n2)
  44. {double **pr=new double* [n1];
  45. for(int i=0;i<n1;i++)
  46. pr[i]=new double[m2];
  47. for(int i=0;i<n1;i++)
  48. for(int j=0;j<m1;j++)
  49. pr[i][j]=0;
  50. for(int i=0;i<n1;i++)
  51. { for(int j=0;j<m2;j++)
  52. {for(int k=0;k<m1;k++)
  53. pr[i][j]+=a[i][k]*b[k][j];
  54. cout<<pr[i][j]<<" ";}
  55. cout<<endl;}
  56. }
  57. else cout<<"error";
  58. system("pause");
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement