Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int enter(int max, int min) {
- int temp = 0;
- bool iscorrect;
- do {
- cin >> temp;
- if ((temp > min - 1) && (temp < max + 1)) {
- iscorrect = false; }
- else {
- cout << "This is a mistake. Please enter again!";
- iscorrect = true;
- }
- }
- while (iscorrect);
- return temp;
- }
- int main() {
- int matrix1[10][10];
- int matrix2[10][10];
- int flag;
- int n;
- cout << "Enter the number of rows and columns in the matrix (N > 1 and N < 11) = ";
- n = enter(10,2);
- cout << "Enter the elements of first matrix a";
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++ ) {
- cout << "Enter a[" << i + 1 << "," << j + 1 << "] = ";
- matrix1[i][j] = enter(200000,-200000);
- }
- }
- cout << "Enter the elements of first matrix b";
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++ ) {
- cout << "Enter b[" << i + 1 << "," << j + 1 << "] = ";
- matrix2[i][j] = enter(200000,-200000);
- }
- }
- cout << "Enter 1 for sum or 2 for subtract matrices ";
- flag = enter(2,1);
- if (flag == 1) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++ ) {
- matrix1[i][j] = matrix1[i][j] + matrix2[i][j];
- }
- }
- }
- else {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++ ) {
- matrix1[i][j] = matrix1[i][j] - matrix2[i][j];
- }
- }
- }
- cout << "New matrix";
- for (int i = 0; i < n; i++) {
- cout << "\n";
- for (int j = 0; j < n; j++ ) {
- cout << matrix1[i][j] << " ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement