| Код | #include <iostream.h> #include <iomanip.h>
#define ROWS 5 #define COLS 5
// по возрастанию bool ascending(int * arr, int size) { for(int i = 1; i < size; i++) if(arr[i] < arr[i - 1]) return false;
return true; }
// по убыванию bool descending(int * arr, int size) { for(int i = 1; i < size; i++) if(arr[i] > arr[i - 1]) return false;
return true; }
int main() { int matr[][COLS] = { 95, 81, 59, 14, 2, 57, 23, 13, 52, 36, 93, 8, 2, 99, 52, 4, 14, 21, 80, 92, 64, 18, 95, 54, 7 }; bool sorted = false;
for(int i = 0; i < ROWS; i++) { for(int j = 0; j < COLS; j++) cout << setw(3) << matr[i][j]; cout << endl; }
for(i = 0; i < ROWS; i++) { bool ascnd = ascending (matr[i], COLS); bool descnd = descending(matr[i], COLS);
int max = ascnd ? matr[i][COLS - 1] : descnd ? matr[i][0] : -1;
if(ascnd || descnd) { cout << "\nLine #" << i + 1 << ": " << max; sorted = true; } }
if(!sorted) cout << "\nbla-bla-bla"; // матрица не содержит упорядоченных строк
cout << endl;
return 0; } |
|