# minimum matrix values | C++

## austinleath

### November 17th, 2021 12:11:15 PM

```					#include <iostream>
using namespace std;

int main() {
const int ROW_SIZE = 2;
const int COLUMN_SIZE = 5;              //establish all variables
int matrix[ROW_SIZE][COLUMN_SIZE];
int minVal;

for (int i = 0; i < ROW_SIZE; ++i)    // for loop to ask user to enter data.
{
for (int h = 0; h < COLUMN_SIZE; ++h) {
cout << "Enter data for row #" << i + 1 << " and column #" << h + 1 << ": ";
cin >> matrix[i][h];
}
}
cout << "You entered: " << endl;
for (int i = 0; i < ROW_SIZE; ++i) //for statements to output the array neatly
{
for (int h = 0; h < COLUMN_SIZE; ++h) {
cout << matrix[i][h] << "\t";
}
cout << endl;
}

cout << "Minimum for each row is: {";
for (int i = 0; i < ROW_SIZE; i++) //for statements to find the minimum in each row
{
minVal = matrix[i][0];

for (int h = 0; h < COLUMN_SIZE; h++) {
if (matrix[i][h] < minVal) // if matrix[i][h] < minVal -> minVal = matrix[i][h];
{
minVal = matrix[i][h];
}
}
cout << minVal << ", ";
}
cout << "}" << endl;

cout << "Minimum for each column is: {";
for (int i = 0; i < COLUMN_SIZE; i++) //for statements to find the minimum in each column
{
minVal = matrix[0][i];
for (int h = 0; h < ROW_SIZE; h++) {
if (matrix[h][i] < minVal) //replaces minVal with array index for that column that is lowest
{
minVal = matrix[h][i];
}
}
cout << minVal << ", ";
}
cout << "}" << endl;

return 0;
}
```