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
|
#include <iostream>
using namespace std;
const int SIZE = 10; // or whatever
//-----------------
int rowMin( int a[SIZE][SIZE], int rows, int cols, int r )
{
int result = a[r][0];
for ( int j = 0; j < cols; j++ ) if ( a[r][j] < result ) result = a[r][j];
return result;
}
//-----------------
int colMax( int a[SIZE][SIZE], int rows, int cols, int c )
{
int result = a[0][c];
for ( int i = 0; i < rows; i++ ) if ( a[i][c] > result ) result = a[i][c];
return result;
}
//-----------------
int main()
{
int m[SIZE][SIZE] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
// int m[SIZE][SIZE] = { { 1, 2, 3 }, { 4, 5, 6 }, { 9, 8, 1 } };
// int m[SIZE][SIZE] = { { 2, 2, 2 }, { 2, 2, 2 }, { 2, 2, 2 } };
int rows = 3, cols = 3;
cout << "Elements satisfying condition: ";
for ( int i = 0; i < rows; i++ )
{
for ( int j = 0; j < cols; j++ )
{
if ( m[i][j] == rowMin( m, rows, cols, i ) && m[i][j] == colMax( m, rows, cols, j ) ) cout << m[i][j] << ' ';
}
}
}
|