-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy path1.cpp
More file actions
42 lines (35 loc) · 733 Bytes
/
1.cpp
File metadata and controls
42 lines (35 loc) · 733 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
// Iterative C++ program to reverse an array
#include <bits/stdc++.h>
using namespace std;
/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
while (start < end)
{
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
/* Utility function to print an array */
void printArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}
/* Driver function to test above functions */
int main()
{
int n;
cin>>n;
int arr[n];
{
for (int i = 0; i < n; i++)
cin >> arr[i] ;
}
rvereseArray(arr,0,n-1);
printArray(arr,n);
}