Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- int* arr = new int[n];
- int current = ((n % 2 == 0) ? n - 2 : n - 1);
- int position = 0;
- while (current >= 0) {//Слева направо до 0
- arr[position] = current;
- current -= 2;
- position++;
- }
- position = n - 1;
- current = ((n % 2 == 0) ? n - 1 : n - 2);
- while (current >= 1) {//Справа налево до 1
- arr[position] = current;
- current -= 2;
- position--;
- }
- for (int i = 0; i < n; i++) {
- cout << i << " - " << arr[i] << endl;
- }
- delete[] arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement