Advertisement
Guest User

Laba_1

a guest
Dec 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3.  
  4. using std::cout;
  5. using std::cin;
  6.  
  7. int main()
  8. {
  9.     int n, m, k, l = 0, temp = 0;
  10.     cout << "Input A(\" \", m): "; cin >> n;
  11.     if (n >= 20) { cout << "Error!"; exit(0); }
  12.     cout << "Input A(" << n << ", \" \"): "; cin >> m;
  13.     if (m >= 20) { cout << "Error!"; exit(0); }
  14.     cout << "Input B(\" \", l): "; cin >> k;
  15.     if (k >= 20) { cout << "Error!"; exit(0); }
  16.     cout << "Input B(" << k << ", \" \"): "; cin >> l;
  17.     if (l >= 20) { cout << "Error!"; exit(0); }
  18.  
  19.     int *APL = new int[n];
  20.     int *BPL = new int[k];
  21.  
  22.     int **matrixA = new int*[n];
  23.     for (int i = 0; i < n; i++)
  24.         matrixA[i] = new int[m];
  25.  
  26.     for (int i = 0; i < n; i++)
  27.         for (int j = 0; j < m; j++)
  28.             matrixA[i][j] = rand() % 10;
  29.  
  30.     for (int i = 0; i < n; i++) {
  31.         for (int j = 0; j < m; j++)
  32.             cout << matrixA[i][j] << " ";
  33.         cout << "\n";
  34.     }
  35.  
  36.     for (int i = 0; i < n; i++) {
  37.         for (int j = 0; j < m; j++) {
  38.             if (matrixA[i][j] >= 0) temp += matrixA[i][j];
  39.         }
  40.         APL[i] = temp;
  41.         temp = 0;
  42.     }
  43.     cout << "\n";
  44.     int **matrixB = new int*[k];
  45.     for (int i = 0; i < k; i++)
  46.         matrixB[i] = new int[l];
  47.  
  48.     for (int i = 0; i < k; i++)
  49.         for (int j = 0; j < l; j++)
  50.             matrixB[i][j] = rand() % 10;
  51.  
  52.     for (int i = 0; i < k; i++) {
  53.         for (int j = 0; j < l; j++)
  54.             cout << matrixB[i][j] << " ";
  55.         cout << "\n";
  56.     }
  57.     cout << "\n";
  58.     for (int i = 0; i < k; i++) {
  59.         for (int j = 0; j < l; j++) {
  60.             if (matrixB[i][j] >= 0) temp += matrixB[i][j];
  61.         }
  62.         BPL[i] = temp;
  63.         temp = 0;
  64.     }
  65.  
  66.     for (int i = 0; i < n; i++)
  67.         cout << *(APL + i) << " ";
  68.     cout << std::endl;
  69.     for (int i = 0; i < k; i++)
  70.         cout << *(BPL + i) << " ";
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement