Advertisement
nikitaxe132

Untitled

Oct 16th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int enter(int max, int min) {
  4.     int temp = 0;
  5.     bool iscorrect;
  6.     do {
  7.         cin >> temp;
  8.         if ((temp > min - 1) && (temp < max + 1)) {
  9.             iscorrect = false;  }
  10.         else {
  11.             cout << "This is a mistake. Please enter again!";
  12.             iscorrect = true;
  13.         }
  14.     }
  15.     while (iscorrect);
  16.     return temp;
  17. }
  18. int main() {
  19.    int matrix1[10][10];
  20.    int matrix2[10][10];
  21.    int flag;
  22.    int n;
  23.    cout << "Enter the number of rows and columns in the matrix (N > 1 and N < 11) = ";
  24.    n = enter(10,2);
  25.    cout << "Enter the elements of first matrix a";
  26.    for (int i = 0; i < n; i++) {
  27.        for (int j = 0; j < n; j++ ) {
  28.            cout << "Enter a[" << i + 1 << "," << j + 1 << "] = ";
  29.            matrix1[i][j] = enter(200000,-200000);
  30.        }
  31.    }
  32.    cout << "Enter the elements of first matrix b";
  33.    for (int i = 0; i < n; i++) {
  34.        for (int j = 0; j < n; j++ ) {
  35.            cout << "Enter b[" << i + 1 << "," << j + 1 << "] = ";
  36.            matrix2[i][j] = enter(200000,-200000);
  37.        }
  38.    }
  39.    cout << "Enter 1 for sum or 2 for subtract matrices ";
  40.    flag = enter(2,1);
  41.    if (flag == 1) {
  42.        for (int i = 0; i < n; i++) {
  43.            for (int j = 0; j < n; j++ ) {
  44.                matrix1[i][j] = matrix1[i][j] + matrix2[i][j];
  45.            }
  46.        }
  47.    }
  48.    else {
  49.        for (int i = 0; i < n; i++) {
  50.            for (int j = 0; j < n; j++ ) {
  51.                matrix1[i][j] = matrix1[i][j] - matrix2[i][j];
  52.            }
  53.        }
  54.    }
  55.    cout << "New matrix";
  56.     for (int i = 0; i < n; i++) {
  57.         cout << "\n";
  58.         for (int j = 0; j < n; j++ ) {
  59.             cout << matrix1[i][j] << "  ";
  60.         }
  61.     }
  62.    return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement