-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0012reverse_array.cpp
More file actions
36 lines (33 loc) · 947 Bytes
/
0012reverse_array.cpp
File metadata and controls
36 lines (33 loc) · 947 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<iostream>
using namespace std;
void reverse(int arr[], int start,int end){
while(start<end){
int temp= arr[start];
arr[start]=arr[end];
arr[end]=temp;
start ++;
end--;
}
}
int main(){
int arr[5]={1,2,3,4,5};
int size=sizeof(arr);
cout<<endl<<"Size Of Array -> "<<size<<endl<<endl;
int getArrayLength = sizeof(arr) / sizeof(int);
cout<<"Non Reversed Array Is : "<<endl;
//array in serial manner
for(int i=0;i<getArrayLength;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
//another apporach to get all array elements
for (int i : arr) {
cout << i << " ";
}cout<<endl<<endl;
cout<<"Reversed Array Is : "<<endl;
// array in reverse manner
reverse(arr,0,getArrayLength-1);
//one line apporach to get all array elements
for (int i : arr) cout << i << " ";
cout<<endl<<endl;
}