#include <iostream>
#include <iomanip>
using namespace std;
const int row = 7;
const int col = 5;
void display(int matrix[][col], int row);
int total(int matrix[][col], int row);
float average(int matrix[][col], int row, int total);
int rowTotal(int matrix[][col], int row, int rowNum);
int colTotal(int matrix[][col], int row, int colNum);
int high_inRow(int matrix[][col], int row, int rowNum);
int low_inRow(int matrix[][col], int row, int rowNum);
int main()
{
int matrix[row][col] = {{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20},
{21, 22, 23, 24, 25},
{26, 27, 28, 29, 30},
{31, 32, 33, 34, 35}};
int colNum = 0;
int rowNum = 0;
display(matrix, row);
cout << "The total sum of the all values = " << total(matrix, row) << endl;
cout << "The average of the all values = " << average(matrix, row, total(matrix, row)) << endl;
cout << "Enter the row number whose sum you want to find:" << endl;
cin >> rowNum;
cout << "The sum of the row " << rowNum << " = " << rowTotal(matrix, row, rowNum) << endl;
cout << "Enter the col number whose sum you want to find:" << endl;
cin >> colNum;
cout << "The sum of the col " << colNum << " = " << colTotal(matrix, row, colNum) << endl;
cout << "Enter the row whose highest value that you want to display:" << endl;
cin >> rowNum;
cout << "The highest value in the row " << rowNum << " :" << high_inRow(matrix, row, rowNum) << endl;
cout << "Enter the row whose highest value that you want to display:" << endl;
cin >> rowNum;
cout << "The lowest value in the row " << rowNum << " :" << low_inRow(matrix, row, rowNum) << endl;
return 0;
}
void display(int matrix[][col], int row)
{
cout << "Matrix :" << endl;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cout << left;
cout << setw(5) << matrix[i][j];
}
cout << endl;
}
cout << endl;
}
int total(int matrix[][col], int row)
{
int total;
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
total += matrix[i][j];
}
}
return total;
}
float average(int matrix[][col], int row, int total)
{
float average;
average = float(total) / (row * col);
return average;
}
int rowTotal(int matrix[][col], int row, int rowNum)
{
int rowTotal;
for (int i = 0; i < col; i++)
{
rowTotal += matrix[rowNum][i];
}
return rowTotal;
}
int colTotal(int matrix[][col], int row, int colNum)
{
int colTotal;
for (int i = 0; i < row; i++)
{
colTotal += matrix[i][colNum];
}
return colTotal;
}
int high_inRow(int matrix[][col], int row, int rowNum)
{
int high_inRow;
high_inRow = matrix[rowNum][0];
for (int i = 0; i < col; i++)
{
if (matrix[rowNum][i] > high_inRow)
{
high_inRow = matrix[rowNum][i];
}
}
return high_inRow;
}
int low_inRow(int matrix[][col], int row, int rowNum)
{
int low_inRow;
low_inRow = matrix[rowNum][0];
for (int i = 0; i < col; i++)
{
if (matrix[rowNum][i] < low_inRow)
{
low_inRow = matrix[rowNum][i];
}
}
return low_inRow;
}