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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <iostream>
using namespace std;
const int SIZE = 4;
//---------------------------------------------------------------
int findMin (int myArray[ ])
{
int minimum = myArray[0];
for(int index = 0; index < SIZE - 1; index++)
{
if(myArray[index] < minimum)
{
minimum = myArray[index];
}
}
return minimum;
}
//---------------------------------------------------------------
void displayArray (int myArray[ ])
{
for(int index = 0; index < SIZE; index++)
{
cout<< "Row "<< index<< " Sum: "<< myArray[index]<< endl;
}
}
//---------------------------------------------------------------
void getRowSums (int matrix[][SIZE], int myArray[ ])
{
int result;
cout<< endl;
for (int rows = 0; rows < SIZE; rows++)
{
for (int cols = 0; cols < SIZE; cols++)
{
result = result + matrix[rows][cols];
myArray[rows] = result;
}
result = 0;
}
}
//---------------------------------------------------------------
void displayMatrix (const int matrix [][SIZE])
{
for (int rows = 0; rows < SIZE; rows++)
{
cout<< endl;
for (int cols = 0; cols < SIZE; cols++)
{
cout<< matrix[rows][cols] << "\t"<< "\t";
}
}
cout<< endl;
}
//---------------------------------------------------------------
int main ()
{
int minimum;
int matrix[SIZE][SIZE] = { {1,2,3,4},
{5,0,2,2},
{8,1,10,3},
{1,4,6,8} };
displayMatrix(matrix);
int myArray[SIZE];
getRowSums(matrix, myArray);
displayArray(myArray);
minimum = findMin(myArray);
cout<< endl<< "The minimum row sum is: "<< minimum;
return (0);
}
| |