Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int findmax(int size, int **M) {
- int start = 0;
- int end = size -1;
- int max = 0;
- bool reduce = true;
- for (int i=0; i<size; i++) {
- for(int j=start; j <= end; j++){
- cout << M[j][i] << setw(2) << "[" << j+1<< "][" <<i+1<<"] index"<<endl;
- if(max < M[j][i]) {
- max = M[j][i];
- }
- }
- if(reduce) {
- start++;
- end--;
- if (start == end || (end -1) == start) {
- reduce = !reduce;
- }
- }else {
- start--;
- end++;
- }
- }
- return max;
- }
- int main ()
- {
- int n,m=0;
- cout << "Введите размерность матрицы: "; cin >> n;
- m=n;
- int **A=new int *[n];
- for (int i=0; i<n; i++)
- A[i]=new int [m];
- cout << "Введите элементы матрицы " << n << 'x' << m << ": " << "\n";
- for (int i=0; i<n; i++){
- for (int j=0; j<m; j++) {
- cout << "A[" << i << "][" << j << "]="; cin >> A[i][j]; cout << endl;
- }
- }
- cout << "--------------------------------------" << endl;
- cout << "Matrix A" << endl;
- for (int i=0; i<n; i++) {
- for(int j=0; j<m; j++)
- cout << A[i][j] << " ";
- cout << endl;
- }
- cout << "--------------------------------------" << endl;
- cout << "Оставшиеся элементы матрицы, после обработки:" << endl;
- int max = findmax(n,A);
- cout << "--------------------------------------" << endl;
- cout << "Максимальный элемент в заданном промежутке = " << max << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement