Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdio.h>
  4. using namespace std;
  5. void print(int A[][7], int D[][5], int N, int M)
  6. {
  7. cout << "Matrix A:" << endl;
  8. for (int i = 0;i < N;i++)
  9. {
  10. for (int j = 0;j < M;j++)
  11. {
  12. cout << A[i][j] << "\t";
  13. }
  14. cout << endl;
  15. }
  16. cout << "Matrix D: " << endl;
  17. for (int i = 0;i < M;i++)
  18. {
  19. for (int j = 0;j < N;j++)
  20. {
  21. cout << D[i][j] << "\t";
  22. }
  23. cout << endl;
  24. }
  25. }
  26. void print2(int** c, int N)
  27. {
  28. for (int i = 0; i < N; i++)
  29. {
  30. for (int j = 0; j < N; j++)
  31. {
  32. cout << c[i][j] << "\t";
  33. }
  34. cout << endl;
  35. }
  36. }
  37. void pr_matrix(int A[][7], int D[][5], int N, int M)
  38. {
  39. int** c = new int* [N];
  40. for (int i = 0; i < N; i++) c[i] = new int[N];
  41. for (int i = 0; i < N; i++)
  42. {
  43. for (int j = 0; j < N; j++)
  44. {
  45. c[i][j] = 0;
  46. }
  47. }
  48. for (int i = 0; i < N; i++)
  49. {
  50. for (int j = 0; j < N; j++)
  51. {
  52. for (int k = 0; k < M; k++)
  53. {
  54. c[i][j] += A[i][k] * D[k][j];
  55. }
  56. }
  57. }
  58. print2(c, N);
  59. }
  60. int main()
  61. {
  62. ifstream file1("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text1.txt");
  63. ifstream file("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text.txt");
  64. if (!file)
  65. {
  66. cout << "File is not open";
  67. return -1;
  68. }
  69. else
  70. {
  71. cout << "File is open" << endl;
  72. const int N = 5;
  73. const int M = 7;
  74. int A[N][M];
  75. int D[M][N];
  76. for (int i = 0;i < N;i++)
  77. {
  78. for (int j = 0;j < M;j++)
  79. {
  80. if (!file.eof())
  81. {
  82. file >> A[i][j];
  83. }
  84. }
  85. }
  86. for (int i = 0;i < M;i++)
  87. {
  88. for (int j = 0;j < N;j++)
  89. {
  90. if (!file1.eof())
  91. {
  92. file1 >> D[i][j];
  93. }
  94. }
  95. }
  96. print(A, D, N, M);
  97. cout << endl;
  98. cout << "Matrix comsposition:" << endl;
  99. pr_matrix(A, D, N, M);
  100. file.close();
  101. system("pause");
  102. return 0;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement