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);
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment