Skip to content

Commit 227b934

Browse files
authored
Merge pull request #21 from Shivansh175/Shivansh175
Issue#4_reverseAnArrayAdded
2 parents 5e8f0cc + 18d7ba2 commit 227b934

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
for(int i=0;i<n;i++)
33+
{
34+
cout<<arr[i]<<" ";
35+
}
36+
return 0;
37+
}
43.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)