was equal to the largest of the elements of the matrix A, which are in the same line and in the same column as the element. I wrote a program that looks for the maximum elements in the columns and rows of the matrix A. Now, in theory, you need to find the maximum elements in those two columns again, but how to do it? And how to fill the matrix B with these elements? I think in that direction?))

int main() { int n; cout << "Order of matrix A is " << endl; cin >> n; cout << endl; int** A = new int* [n]; for (int i = 0; i < n; i++) A[i] = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { A[i][j] = rand() % 100; cout << setw(3) << A[i][j] << " "; } cout << endl; } cout << endl; int max; int** B = new int* [n]; max = A[0][0]; for (int c = 0; c < n; c++) { for (int a = 0; a < n; a++) { if (max < A[c][a]) max = A[c][a]; } cout << max << endl; max = 0; } cout << endl; for (int a = 0; a < n; a++) { for (int c = 0; c < n; c++) { if (max < A[c][a]) max = A[c][a]; } cout << max << endl; max = 0; } return 0; } 
  • Get two arrays: one - the size of the row of the matrix A, the other - the size of the column of the matrix A. Fill these arrays with the maximum values ​​in the columns and rows, respectively. To find the values ​​of the elements of matrix B, choose the larger of the two numbers that are in the corresponding indices of those two arrays. - Igor

1 answer 1

We make two arrays (vectors, ...) - in one we collect the maximum values ​​of the rows, in the other - the columns. Let's say it's r[] and c[] . Then B[i][j] is the maximum of r[i] and c[j] .

It's simple :)

In my opinion, so (c) Pooh

Update Solution:

 int main() { int n; cout << "Order of matrix A: "; cin >> n; int** A = new int* [n]; for (int i = 0; i < n; i++) A[i] = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { A[i][j] = rand() % 100; cout << setw(3) << A[i][j] << " "; } cout << endl; } cout << endl; int** B = new int* [n]; for (int i = 0; i < n; i++) B[i] = new int[n]; int * r = new int[n]; int * c = new int[n]; for (int i = 0; i < n; i++) { r[i] = c[i] = INT_MIN; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (A[i][j] > r[i]) r[i] = A[i][j]; if (A[i][j] > c[j]) c[j] = A[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { B[i][j] = (r[i] > c[j]) ? r[i] : c[j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << setw(3) << B[i][j] << " "; } cout << endl; } cout << endl; delete[] r; delete[] c; for (int i = 0; i < n; i++) { delete[] A[i]; delete[] B[i]; } delete[] A; delete[] B; } 
  • Thanks for the answer! But the problem is that I can not collect these maximum elements in two arrays. I can not understand what changes need to be made in my cycle to do this. (Sorry to stupid a little: I'm just studying the 1st semester just C ++: D) - Unknown
  • Well, see the updated answer ... If you like it - mark it as accepted, and good night :) - Harry
  • Thank you so much! And good night to you) And how to mark your answer? - Unknown Nov.
  • To the left of the answer there is a “bird”, which is clicked if the answer is an answer to a question, and two triangles are for an opinion about the usefulness / harmfulness of the answer. Triangles mzh press each, "bird" - only the author of the question. - Harry