fork download
  1. #include <stdio.h>
  2.  
  3. void reverseArr(int arr[], int start, int end)
  4. {
  5. int temp = 0;
  6.  
  7. while (start < end) {
  8. temp = arr[start];
  9. arr[start] = arr[end];
  10. arr[end] = temp;
  11.  
  12. start++;
  13. end--;
  14. }
  15.  
  16. }
  17.  
  18. int main()
  19. {
  20. int arr[] = {1, 2, 3, 4, 5, 6, 7};
  21. int rotate = 2;
  22. int size = 7;
  23. int i = 0;
  24.  
  25. reverseArr(arr, 0, rotate - 1);
  26. reverseArr(arr, rotate, size - 1);
  27. reverseArr(arr, 0, size - 1);
  28.  
  29. for (i = 0; i < size; i++) {
  30. printf("%d ", arr[i]);
  31. }
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
3 4 5 6 7 1 2