Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void Fill(int** arr, int lines, int cols) {
- for (int i = 0; i < lines; i++) {
- for (int j = 0; j < cols; j++) {
- arr[i][j] = rand() % 100;
- }
- }
- }
- void Print(int** arr, int lines, int cols) {
- for (int i = 0; i < lines; i++) {
- for (int j = 0; j < cols; j++) {
- cout << arr[i][j] << '\t';
- }
- cout << endl;
- }
- cout << endl;
- }
- void Rotate(int**& arr, int& lines, int& cols) {
- int** temp = new int* [cols];
- for (int i = 0; i < cols; i++) {
- temp[i] = new int[lines];
- for (int j = 0; j < lines; j++) {
- temp[i][j] = arr[lines - j - 1][i];
- }
- }
- for (int i = 0; i < lines; i++) {
- delete[] arr[i];
- }
- delete[] arr;
- arr = temp;
- int buf = lines;
- lines = cols;
- cols = buf;
- }
- int main() {
- srand(time(NULL));
- int lines = 3, cols = 4;
- int** arr = new int* [lines];
- for (int i = 0; i < lines; i++) {
- arr[i] = new int[cols];
- }
- Fill(arr, lines, cols);
- Print(arr, lines, cols);
- Rotate(arr, lines, cols);
- Print(arr, lines, cols);
- for (int i = 0; i < lines; i++) {
- delete[] arr[i];
- }
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement