We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5e8f0cc + 18d7ba2 commit 227b934Copy full SHA for 227b934
Reverse_an_array/Reverse_an_array.cpp
@@ -0,0 +1,37 @@
1
+#include<iostream>
2
+using namespace std;
3
+int main()
4
+{
5
+ //Take an array as input
6
+ cout<<"Size of array is: ";
7
+ int n;
8
+ cin>>n;
9
+
10
+ //Declaring an array of size n
11
+ int arr[n];
12
13
+ //Taking the array from user
14
+ cout<<"Enter the array: ";
15
+ for(int i=0;i<n;i++)
16
+ {
17
+ cin>>arr[i];
18
+ }
19
20
+ //Reversing the entered array
21
+ for(int i=0;i<n/2;i++)
22
23
+ int help;
24
25
+ //swapping ith element from start with ith element from last
26
+ help=arr[i];
27
+ arr[i]=arr[n-i-1];
28
+ arr[n-1-i]=help;
29
30
31
+ //printing the reversed array
32
33
34
+ cout<<arr[i]<<" ";
35
36
+ return 0;
37
+}
Reverse_an_array/Reverse_an_array.exe
43.8 KB
0 commit comments