-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathreverse.cpp
More file actions
36 lines (36 loc) · 700 Bytes
/
reverse.cpp
File metadata and controls
36 lines (36 loc) · 700 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
#include<bits/stdc++.h>
using namespace std;
void reverseArray(int a[],int start , int end)
{
while(start<end)
{
swap(a[start],a[end]);
start++;
end--;
}
}
void print(int a[],int n)
{
for(int i=0;i<n;i++)
{
cout<< a[i] << " ";
}
cout<<endl;
}
int main()
{
// int arr[] = {2,99,5,6,9,75,3};
// int n = sizeof(arr)/(sizeof(arr[0]));
int arr[20],n,i;
cout<<"enter the range:\n";
cin>>n;
cout<<"enter the elements in the array:\n";
for(i=0;i<n;i++)
cin>>arr[i];
// cout<<" reverse: ";
print(arr,n);
reverseArray(arr,0,n-1);
cout<<"after reverse: ";
print(arr,n);
return 0;
}