Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void print(int** arr, int row, int col) {
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- }
- void fill(int** arr, int row, int col) {
- for (int i = 0; i < row; i++) {
- for (int j = 0; j < col; j++) {
- arr[i][j] = rand() % 10;
- }
- }
- }
- void change_column(int** arr, int row, int index1, int index2) {
- for (int i = 0; i < row; i++) {
- int temp = arr[i][index1];
- arr[i][index1] = arr[i][index2];
- arr[i][index2] = temp;
- }
- }
- int main() {
- setlocale(LC_ALL, "ru");
- srand(time(NULL));
- int row = 5, col = 5;
- int** arr = new int* [row];
- for (int i = 0; i < row; i++) {
- arr[i] = new int[col];
- }
- fill(arr, row, col);
- print(arr, row, col);
- change_column(arr, row, 0, 1);
- print(arr, row, col);
- for (int i = 0; i < row; i++) {
- delete[] arr[i];
- }
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement