Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- <3
- UPD:
- Not the best solution.
- */
- #include <iostream>
- using namespace std;
- int main() {
- int size;
- cout << "Enter array size: ";
- cin >> size;
- int *arr = new int[size];
- cout << "Enter " << size << " elements with a space: ";
- for (int i = 0; i < size; i++)
- cin >> arr[i];
- int n;
- cout << "Enter n by which the array will be shifted: ";
- cin >> n;
- cout << "Old array: ";
- for (int i = 0; i < size; i++)
- cout << arr[i] << " ";
- for (int i = 0; i < n; i++) {
- int *buffArr = new int[size];
- for (int j = 1; j < size; j++) {
- buffArr[j] = arr[j-1];
- }
- buffArr[0] = arr[size-1];
- for (int j = 0; j < size; j++) {
- arr[j] = buffArr[j];
- }
- delete[] buffArr;
- }
- cout << endl << "New array: ";
- for (int i = 0; i < size; i++)
- cout << arr[i] << " ";
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement