forked from Andyy-18/CPP-BASICS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseanArray.cpp
More file actions
49 lines (38 loc) · 828 Bytes
/
ReverseanArray.cpp
File metadata and controls
49 lines (38 loc) · 828 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
47
48
49
#include<bits/stdc++.h>
using namespace std;
void reverse(int arr[], int n){
int start = 0;
int end = n-1;
while(start <= end){
swap(arr[start],arr[end]);
start++;
end--;
}
}
void printArray(int arr[], int n){
cout<<"Reverse of the array : \n";
for(int i=0; i<n; i++){
cout<<arr[i]<<" ";
}
cout<<endl;
}
int main()
{
int n;
cout<<"Enter the size of array : "<<endl;
cin>>n;
int arr[100];
cout<<"Enter an array : \n";
for(int i=0; i<n; i++){
cin>>arr[i];
}
reverse(arr,n);
printArray(arr,n);
/*int arr[6] = {2,7,-2,5,9,-15};
int brr[5] = {1,6,-3,4,8};
reverse(arr,6);
reverse(brr,5);
printArray(arr,6);
printArray(brr,5);*/
return 0;
}