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

Question #27693
how does this programme work #include <cmath> #include <ctime> #include <cstdlib> #include <iomanip> #include <iostream> #include <conio.h> using namespace std; const int MATRIX_SIZE = 5; void print_matrix(int (&matrix)[MATRIX_SIZE][MATRIX_SIZE]) { for (int x = 0; x < MATRIX_SIZE; x++) { for (int y = 0; y < MATRIX_SIZE; y++) cout << setw(4) << matrix[x][y]; cout << endl; } cout << endl; } int find_max_element_row(int (&matrix)[MATRIX_SIZE][MATRIX_SIZE]) { int row = 0; int maxElement = -1; for (int x = 0; x < MATRIX_SIZE; x++) for (int y = 0; y < MATRIX_SIZE; y++) if (abs(matrix[x][y]) > 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 < 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 < MATRIX_SIZE; x++) for (int y = 0; y < MATRIX_SIZE; y++) matrix[x][y] = rand() % 30; cout << "The initial matrix:" << endl; print_matrix(matrix); swap_rows(matrix, find_max_element_row(matrix), 0); cout << "The resulting matrix:" << endl; print_matrix(matrix); _getch(); return 0; }
0
Expert's answer

Not answered

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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS