#include #include #include #include using std::cout; using std::cin; using std::endl; #define ROWS 10 #define COLS 12 //Prototype Section void display(int [][COLS]); int getSmallest(int [][COLS]); int getLargest(int [][COLS]); int getMaxRow(int [][COLS]); void main() { int numbers[ROWS][COLS]; srand(time(NULL)); for (int x = 0; x < ROWS; x++) for (int y =0; y < COLS; y++) { numbers[x][y] = rand() % 100; } display(numbers); cout << "The smallest value is ... " << getSmallest(numbers); cout << endl << endl; cout << "The Largest value is ... " << getLargest(numbers); cout << endl << endl; cout << "The Max Row is ... " << getMaxRow(numbers); cout << endl << endl; getch(); } void display(int array[][COLS]) { int sum; for (int x = 0; x < ROWS; x++) { for (int y = 0; y < COLS; y++) { cout << array[x][y] << " "; } sum = array[x][0]; for ( int k = 1; k < COLS; k++) { sum += array[x][k]; } cout << " ........ " << sum; cout << endl; } cout <<"\n\n"; } int getSmallest(int array[][COLS]) { int min = array[0][0]; for (int x = 0; x < ROWS; x++) { for (int y = 0; y < COLS; y++) { if ( array[x][y] < min ) min = array[x][y]; } } return min; } int getLargest(int array[][COLS]) { int max = array[0][0]; for (int x = 0; x < ROWS; x++) { for (int y = 0; y < COLS; y++) { if ( array[x][y] > max ) max = array[x][y]; } } return max; } int getMaxRow(int array[][COLS]) { int maxRow, rowSum, sum; maxRow = 0; rowSum = array[0][0]; //Compute the sum for the first row and store the value in rowSum for (int x = 1; x < COLS; x++) rowSum += array[0][x]; //Proceed to the other rows for (int x = 1; x < ROWS; x++) { sum = array[x][0]; for (int y = 1; y < COLS; y++) { sum += array[x][y]; } if (sum > rowSum) { rowSum = sum; maxRow = x; } } return maxRow+1; }