task7.cpp 725 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include <iostream>
  2. void reverseAroundMiddle(int* arr, int size) {
  3. int mid = (size + 1) / 2;
  4. int* temp = new int[size];
  5. for (int i = 0; i < mid; ++i) {
  6. temp[i] = arr[mid + i];
  7. }
  8. for (int i = mid; i < size; ++i) {
  9. temp[i] = arr[i - mid];
  10. }
  11. for (int i = 0; i < size; ++i) {
  12. arr[i] = temp[i];
  13. }
  14. delete[] temp;
  15. }
  16. int main() {
  17. int arr[] = {1, 2, 3, 4, 5, 6};
  18. int size = sizeof(arr) / sizeof(arr[0]);
  19. reverseAroundMiddle(arr, size);
  20. std::cout << "{";
  21. for (int i = 0; i < size; ++i) {
  22. std::cout << arr[i];
  23. if (i < size - 1) {
  24. std::cout << ", ";
  25. }
  26. }
  27. std::cout << "}" << std::endl;
  28. return 0;
  29. }