Advertisement
Polnochniy

Untitled

Jan 22nd, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. using namespace std;
  4. const int N = 3;
  5. const int P = 4;
  6. int main()
  7. {
  8. int a[N][P];
  9. int b[N][P]; // чтобы провести сумму матриц , то матрицы должны быть равны
  10. int sum[N][P];
  11. int F;
  12. setlocale(LC_ALL, "Rus");
  13. srand(time(NULL));
  14. cout << "Введите число " << endl;
  15. cin >> F;
  16. cout << " Найтие cумму матриц . " << 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() % 12;
  24. cout << a[i][j] << " ";
  25. }
  26. cout << endl;
  27. }
  28. cout << endl;
  29. cout << "Для матрицы B " << endl;
  30. for (int i = 0; i < N; i++)
  31. {
  32. for (int j = 0; j < P; j++)
  33. {
  34. b[i][j] = rand() % 12;
  35. cout << b[i][j] << " ";
  36. }
  37. cout << endl;
  38. }
  39. cout << endl;
  40. cout << "Умножение матрицы B на число равно = " << endl;
  41. for (int i = 0; i < N; i++)
  42. {
  43. for (int j = 0; j < P; j++)
  44. {
  45. b[i][j] = b[i][j] * F;
  46. cout << b[i][j]<< " ";
  47. }
  48.  
  49. cout << endl;
  50. }
  51. cout << endl;
  52. cout << "Сумма матриц равна = " << endl;
  53. for (int i = 0; i < N; i++)
  54. {
  55. for (int j = 0; j < P; j++)
  56. {
  57. sum[i][j] = a[i][j] + b[i][j];
  58. cout << sum[i][j] << " ";
  59. }
  60. cout << endl;
  61. }
  62. cout << endl;
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement