Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int size, k, x, r, t;
- cout << "Введите размер массива: ";
- cin >> size;
- if (!cin){
- cout << "Error";
- return 1;
- }
- cout << "\nВведите шаг: ";
- cin >> k;
- if (!cin){
- cout << "Error";
- return 1;
- }
- k %= size;
- int *arr = new int[size];
- for (int i = 0; i<size; i++) {
- arr[i] = (rand() % 10 + 1);
- cout << arr[i] << "\t";
- }
- cout << endl;
- for (int i = k; (i - size) < k; i++) {
- if (i<size) {
- t = arr[i]; //сохраняем в переменнную
- arr[i] = arr[i - k]; //меняем
- arr[i - k] = t; //меняем
- }
- else {
- //тут продумать, что происходит, когда идём за массив
- t = arr[i - size];
- arr[i - size] = arr[];
- }
- }
- delete[]arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement