#include<iostream> using namespace std; void reverse(int arr[], int n, int s, int e) { if (s > e) { return; } swap(arr[s], arr[e]); s++; e--; reverse(arr, n, s, e); } int main() { int arr[4] = { 1,2,3,4 }; int s = 0; int e = 3; int n = 4; reverse(arr, n, s, e); for (int i = 0; i < n; i++) { cout << arr[i]<<" "; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter