forked from chayanika840/Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPP
More file actions
37 lines (30 loc) · 563 Bytes
/
CPP
File metadata and controls
37 lines (30 loc) · 563 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
//Reverse an array
#include <bits/stdc++.h>
using namespace std;
void rvereseArray(int arr[], int start, int end)
{
while (start < end)
{
int temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
void printArray(int arr[], int size)
{
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}
int main()
{
int arr[] = {1, 2, 3, 4, 5, 6,7,8};
int n = sizeof(arr) / sizeof(arr[0]);
printArray(arr, n);
rvereseArray(arr, 0, n-1);
cout << "Reversed array is" << endl;
printArray(arr, n);
return 0;
}