fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void reverseArray(int arr[], int start, int end){
  5. // Base case
  6. if(start >= end)
  7. return;
  8.  
  9. // Swap
  10. int temp = arr[start];
  11. arr[start] = arr[end];
  12. arr[end] = temp;
  13.  
  14. // Recursive call
  15. reverseArray(arr, start + 1, end - 1);
  16. }
  17.  
  18. int main()
  19. {
  20. int arr[] = {1,2,3,4,5};
  21. int n = 5;
  22.  
  23. reverseArray(arr,0,n-1);
  24.  
  25. for(int i=0;i<n;i++)
  26. cout<<arr[i]<<" ";
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
5 4 3 2 1