forked from TARANG0503/DSA-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayReversal.cpp
More file actions
43 lines (28 loc) · 729 Bytes
/
Copy pathArrayReversal.cpp
File metadata and controls
43 lines (28 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
int reverse(int arr[], int start, int end) {
int temp;
if(start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
// recursive function call
reverse(arr, start+1, end-1);
}
return 0;
}
int main() {
int n, arr[100], i;
cout << "Enter the size of an array \n";
cin >> n;
cout << "Enter an element of an array \n";
for(i = 0; i < n; i++) {
cin >> arr[i];
}
reverse(arr, 0, n-1);
cout << "Reverse of an array is \n";
for(i = 0; i < n; i++) {
cout << arr[i] << " ";
}
return 0;
}