Advertisement
Polnochniy

Untitled

Jan 22nd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4. const int N = 3;
  5. const int P = 5;
  6. const int Q = 5;
  7. const int W = 4; // чтобы провести умножение , то нужно чтобы количество строк 1 матрицы совпадало с количеством столбцов 2 матрицы
  8.  
  9. int main()
  10. {
  11. int a[N][P];
  12. int b[Q][W];
  13. int c[P][Q];
  14. setlocale(LC_ALL, "Rus");
  15. srand(time(NULL));
  16. cout << " Найтие умножение двух матриц " << endl;
  17. cout << "Вывод элементов" << endl;
  18. cout << "Для матрицы А" << endl;
  19. for (int i = 0; i < N; i++)
  20. {
  21. for (int j = 0; j < P; j++)
  22. {
  23. a[i][j] = rand() % 6;
  24. cout << a[i][j] << " ";
  25. }
  26. cout << endl;
  27. }
  28. cout << "Для матрицы B" << endl;
  29. for (int i = 0; i < Q; i++)
  30. {
  31. for (int j = 0; j < W; j++)
  32. {
  33. b[i][j] = rand() % 6;
  34. cout << b[i][j] << " ";
  35. }
  36. cout << endl;
  37. }
  38. cout << "Умножение матриц равно = " << endl;
  39. for (int i = 0; i < N; i++)
  40. {
  41. for (int j = 0; j<W; j++)
  42. {
  43. c[i][j] = 0;
  44. for (int k = 0; k < Q; k++)
  45. {
  46. c[i][j] += a[i][k] * b[k][j];
  47. }
  48. cout << c[i][j] << " ";
  49. }
  50. cout << endl;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement