Advertisement
Piranha887

Untitled

Dec 9th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void create(int** a, int n, char p) {
  7. for (int i = 0; i < n; i++) {
  8. for (int j = 0; j < n; j++) {
  9. cout << p << "[" << i << "][" << j << "]="; cin >> a[i][j];
  10. }
  11. }
  12. }
  13. bool check(int** a, int n) {
  14. bool E = false;
  15. for (int i = 0; i < n && !E; i++) {
  16. bool A = true;
  17. for (int j = 0; j < n && A; j++) {
  18. if (a[i][j] >= 0) { A = false; }
  19. }
  20. if (A) { E = true;}
  21. }
  22. return E;
  23. }
  24. void sum(int** a, int** b,int **c, int n) {
  25. for (int i = 0; i < n; i++) {
  26. for (int j = 0; j < n; j++) {
  27. c[i][j] = a[i][j] + b[i][j];
  28. }
  29. }
  30. }
  31. void mult(int** a, int** b, int** c, int n) {
  32. for (int i = 0; i < n; i++)
  33. for (int j = 0; j < n; j++) {
  34. c[i][j] = 0;
  35. for (int k = 0; k < n; k++)
  36. c[i][j] += a[i][k] * b[k][j];
  37. }
  38. }
  39.  
  40. void show(int** a, int n) {
  41. for (int i = 0; i < n; i++) {
  42. for (int j = 0; j < n; j++) {
  43. cout << a[i][j] << " ";
  44. }
  45. cout << "\n";
  46. }
  47. }
  48. int main() {
  49. setlocale(LC_ALL, "Ru");
  50. int** a, ** b, ** c, n;
  51. cout << "Введите размер квадратных матриц:";
  52. cin >> n;
  53. a = new int* [n];
  54. b = new int* [n];
  55. c = new int* [n];
  56. for (int i = 0; i < n; i++) {
  57. a[i] = new int[n];
  58. b[i] = new int[n];
  59. c[i] = new int[n];
  60. }
  61. cout << "Заполните массив А:\n";
  62. create(a,n,'А');
  63. cout << "Заполните массив В:\n";
  64. create(b, n, 'В');
  65. cout << "Массив А:\n";
  66. show(a, n);
  67. cout << "Массив B:\n";
  68. show(b, n);
  69.  
  70. if (check(a, n)) {
  71. cout << "Сумма:\n";
  72. sum(a, b, c, n);
  73. show(c, n);
  74. }
  75. else {
  76. cout << "Произведение:\n";
  77. mult(a, b, c, n);
  78. show(c, n);
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement