Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
97
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[][5], 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 c[][5], int D[][5],const int N, int M)
  38. {
  39.  
  40. for (int i = 0; i < N; i++)
  41. {
  42. for (int j = 0; j < N; j++)
  43. {
  44. for (int k = 0; k < M; k++)
  45. {
  46. c[i][j] += A[i][k] * D[k][j];
  47. }
  48. }
  49. }
  50. print2(c, N);
  51. }
  52. int main()
  53. {
  54. ifstream file1("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text1.txt");
  55. ifstream file("C:\\Users\\Irinda\\source\\repos\\Задание 1\\text.txt");
  56. if (!file)
  57. {
  58. cout << "File is not open";
  59. return -1;
  60. }
  61. else
  62. {
  63. cout << "File is open" << endl;
  64. const int N = 5;
  65. const int M = 7;
  66. int A[N][M];
  67. int D[M][N];
  68. int c[N][N];
  69. for (int i = 0;i < N;i++)
  70. {
  71. for (int j = 0;j < M;j++)
  72. {
  73. if (!file.eof())
  74. {
  75. file >> A[i][j];
  76. }
  77. }
  78. }
  79. for (int i = 0;i < M;i++)
  80. {
  81. for (int j = 0;j < N;j++)
  82. {
  83. if (!file1.eof())
  84. {
  85. file1 >> D[i][j];
  86. }
  87. }
  88. }
  89. for (int i = 0; i < N; i++)
  90. {
  91. for (int j = 0; j < N; j++)
  92. {
  93. c[i][j] = 0;
  94. }
  95. }
  96. print(A, D, N, M);
  97. cout << endl;
  98. cout << "Matrix comsposition:" << endl;
  99. pr_matrix(A,c, D, N, M);
  100. file.close();
  101. system("pause");
  102. return 0;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement