в первом вводе вводятся количество строк и столбцов
#include <iostream>
using namespace std;
int main() {
int colss,rowss;
cin >> cols >> rows;
int a[cols][rows];
for(int i = 0; i<cols; i++){
for(int j = 0; j<rows; j++){
cin >> a[i][j];
}
}
int b[rows][cols];
for(int i = 0; i<rows; i++){
for(int j = 0; j<cols; j++){
b[i][j] = a[j][i];
}
}
for(int i = 0; i<cols; i++){
for(int j = 0; j<rows; j++){
cout << b[i][j] << " ";
}
cout << endl;
}
return 0;
}
signed main(){
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int> (m));
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
int col = 0, mx = a[0][0];
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(a[i][j] > mx){
mx = a[i][j];
col = j;
}
}
}
for(int i = 0; i < n; i++)
swap(a[i][0], a[i][col]);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cout << a[i][j] << " ";
cout << "\n";
}
}
var a:array[1..n] of integer;
i,h:integer;
begin
Randomize;
for i:=1 to n do begin
a[i]:=random(51);
write(a[i],' ');
end;
writeln;
for i:=1 to n div 2 do
begin
h:=a[2*i-1]; a[2*i-1]:=a[2*i]; a[2*i]:=h
end;
for i:=1 to n do write(a[i],' ');
writeln;
end.
Пример:
8 7 12 28 22 50 15 36 6 40
7 8 28 12 50 22 36 15 40 6