-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_reverse.cpp
More file actions
56 lines (54 loc) · 1.29 KB
/
array_reverse.cpp
File metadata and controls
56 lines (54 loc) · 1.29 KB
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
50
51
52
53
54
55
// REVERSING AN ARRAY
// #include<iostream>
// using namespace std;
// int main(){
// int arr[10],n;
// cout<<"Enter size of array : ";
// cin>>n;
// cout<<"Enter elements of array : ";
// for(int i=0;i<n;i++)
// cin>>arr[i];
// cout<<"The elements of array : ";
// for(int i=0;i<n;i++){
// cout<<" "<<arr[i];
// }
// cout<<endl;
// int s=0;
// int e=n-1;
// while(s<=e){
// swap(arr[s],arr[e]);
// s++;
// e--;
// }
// cout<<"The elements of array after reversing are: ";
// for(int i=0;i<n;i++)
// cout<<" "<<arr[i];
// return 0;
// }
// REVERSING ALTERNATE ELEMENTS OF AN ARRAY
#include<iostream>
using namespace std;
int main(){
int arr[10],n;
cout<<"Enter size of array : ";
cin>>n;
cout<<"Enter elements of array : ";
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<"The elements of array : ";
for(int i=0;i<n;i++){
cout<<" "<<arr[i];
}
cout<<endl;
int a=0;
int b=1;
while((a<=(n-2))&&(b<=(n-1))){
swap(arr[a],arr[b]);
a+=2;
b+=2;
}
cout<<"The elements of array after reversing are: ";
for(int i=0;i<n;i++)
cout<<" "<<arr[i];
return 0;
}