-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.cpp
More file actions
46 lines (41 loc) · 784 Bytes
/
reverse.cpp
File metadata and controls
46 lines (41 loc) · 784 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
44
45
46
#include<iostream>
using namespace std;
void reverse(int arr[],int s,int e,int n)
{
int i,temp;
for(i=0;i<n/2;i++)
{
temp = arr[e];
arr[e] = arr[s];
arr[s] = temp;
s=s+1;
e=e-1;
}
cout<<"\nArray After reverse ";
for(i=0;i<n;i++)
{
cout<<arr[i];
}
}
int main()
{
int i,n;
cout<<"Enter the size of the array";
cin>>n;
int a[n],startindex,endindex;
cout<<"\nEnter the array elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n The entered array is";
for(i=0;i<n;i++)
{
cout<<"\n";
cout<<a[i];
}
startindex=0;
endindex=n-1;
reverse(a,startindex,endindex,n);
return 0;
}