Поміняти місцями елементи першого і останнього стовпців на с++
Ответы
#include <iostream>
using namespace std;
int main()
{
int r = 3, c = 3;
int arr[r][c];
cout << "Enter matrix elements: " << endl;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin >> arr[i][j];
}
}
cout << "Original matrix: " << endl;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
// Swapping first and last column elements of the matrix.
for (int i = 0; i < r ; i++) {
int temp = arr[i][0];
arr[i][0] = arr[i][c - 1];
arr[i][c - 1] = temp ;
}
cout << "\nMatrix after swapping first and last column: \n";
for (int i = 0 ; i < r ; i++ ) {
for (int j = 0 ; j < c ; j++ ) {
cout << arr[i][j] << " " ;
} cout << endl ; // new line after each row.
} return 0 ; // successful termination of program.
}
#include <iostream>
using namespace std;
void zamina(double arr[3][6], double temp) {
const int a = 3;
for (int i = 1; i<= a; i++) {
for (int j = 1; j<= 2*a; j++) {
cin >> arr[i][j];
}
}
for (int i = 1; i<= a; i++) {
temp = arr[i][1];
arr[i][1] = arr[i][6];
arr[i][6] = temp;
}
for (int i = 1; i<= a; i++) {
for (int j = 1; j<= 2*a; j++) {
cout << arr[i][j] << endl;
}
}
}
int main() {
double arr[3][6], temp;
zamina(arr, temp);
}