Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int findmax(int size, int **M) {
  6.          int start = 0;
  7.         int end = size -1;
  8.         int max = 0;
  9.         bool reduce = true;
  10.         for (int i=0; i<size; i++) {
  11.      
  12.             for(int j=start; j <= end; j++){
  13.                 cout << M[j][i] << setw(2) << "[" << j+1<< "][" <<i+1<<"] index"<<endl;
  14.                 if(max < M[j][i]) {
  15.                     max = M[j][i];
  16.                     }
  17.             }
  18.             if(reduce) {
  19.                 start++;
  20.                 end--;
  21.                 if (start == end || (end -1) == start) {
  22.                     reduce = !reduce;
  23.                 }
  24.             }else {
  25.                 start--;
  26.                 end++;
  27.             }
  28.         }
  29.         return max;
  30.     }
  31.  
  32. int main ()
  33. {
  34.    
  35.    
  36.    
  37.     int n,m=0;
  38.     cout << "Введите размерность матрицы: "; cin >> n;
  39.     m=n;
  40.     int **A=new int *[n];
  41.     for (int i=0; i<n; i++)
  42.         A[i]=new int [m];
  43.    
  44.     cout << "Введите элементы матрицы " << n << 'x' << m << ": " << "\n";
  45.     for (int i=0; i<n; i++){
  46.         for (int j=0; j<m; j++) {
  47.             cout << "A[" << i << "][" << j << "]="; cin >> A[i][j]; cout << endl;
  48.         }
  49.     }
  50.     cout << "--------------------------------------" << endl;
  51.     cout << "Matrix A" << endl;
  52.     for (int i=0; i<n; i++) {
  53.         for(int j=0; j<m; j++)
  54.             cout << A[i][j] << " ";
  55.         cout << endl;
  56.     }
  57.    
  58.     cout << "--------------------------------------" << endl;
  59.     cout << "Оставшиеся элементы матрицы, после обработки:" << endl;
  60.  
  61.    int max = findmax(n,A);
  62.  
  63.     cout << "--------------------------------------" << endl;
  64.     cout << "Максимальный элемент в заданном промежутке = " << max << endl;
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement