87 097
Assignments Done
98.6%
Successfully Done
In May 2020

# Answer to Question #27693 in C++ for asare patrick

Question #27693
how does this programme work #include &lt;cmath&gt; #include &lt;ctime&gt; #include &lt;cstdlib&gt; #include &lt;iomanip&gt; #include &lt;iostream&gt; #include &lt;conio.h&gt; using namespace std; const int MATRIX_SIZE = 5; void print_matrix(int (&matrix)[MATRIX_SIZE][MATRIX_SIZE]) { for (int x = 0; x &lt; MATRIX_SIZE; x++) { for (int y = 0; y &lt; MATRIX_SIZE; y++) cout &lt;&lt; setw(4) &lt;&lt; matrix[x][y]; cout &lt;&lt; endl; } cout &lt;&lt; endl; } int find_max_element_row(int (&matrix)[MATRIX_SIZE][MATRIX_SIZE]) { int row = 0; int maxElement = -1; for (int x = 0; x &lt; MATRIX_SIZE; x++) for (int y = 0; y &lt; MATRIX_SIZE; y++) if (abs(matrix[x][y]) &gt; maxElement) { maxElement = abs(matrix[x][y]); row = x; } return row; } void swap_rows(int (&matrix)[MATRIX_SIZE][MATRIX_SIZE], int rowA, int rowB) { int tmp; for (int y = 0; y &lt; MATRIX_SIZE; y++) { tmp = matrix[rowA][y]; matrix[rowA][y] = matrix[rowB][y]; matrix[rowB][y] = tmp; } } int main() { int matrix[5][5]; srand(time(NULL)); for (int x = 0; x &lt; MATRIX_SIZE; x++) for (int y = 0; y &lt; MATRIX_SIZE; y++) matrix[x][y] = rand() % 30; cout &lt;&lt; &quot;The initial matrix:&quot; &lt;&lt; endl; print_matrix(matrix); swap_rows(matrix, find_max_element_row(matrix), 0); cout &lt;&lt; &quot;The resulting matrix:&quot; &lt;&lt; endl; print_matrix(matrix); _getch(); return 0; }
0

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!