- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
#include <iostream>
using namespace std;
/*Replace matricca's rows*/
int** inputMatr(int** arr, unsigned m, unsigned n){
for (unsigned i = 0; i < m; ++i)
for (unsigned j = 0; j < n; ++j)
cin >> arr[i][j];
return arr;
}
int** outputMatr(int** arr, int m, int n){
for (int i = 0; i < m; ++i){
for (int j = 0; j < n; ++j)
cout << arr[i][j] << " ";
cout << endl;
}
return arr;
}
int** allocateMatr(unsigned m, unsigned n){
int** p = new int*[m];
for (unsigned i = 0; i < m; ++i)
p[i] = new int[n];
return p;
}
int** swapRows(int** arr, unsigned m, unsigned n){
int** p = new int*[m];
for (unsigned i = 0; i < m; ++i){
p[i] = new int[n];
}
unsigned ai=m;
ai--;
for (unsigned i = 0; i < m/2; i++,ai--){
for (unsigned j = 0; j < n; j++){
p[i][j]= arr[i][j];
arr[i][j]=arr[ai][j];
arr[ai][j]=p[i][j];
}
}
return arr;
}
int main() {
int row,column;
cout << "Input size matr " << endl;
cin >> row >> column;
int** array = allocateMatr(row,column);
inputMatr(array,row ,column);
swapRows(array,row,column);
outputMatr(array, row ,column);
return 0;
}
Поменять строки матрицы(1ую с последней,вторую с предпоследней и т.д)
Комментарии (0) RSS
Добавить комментарий