-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_session_reverseOrder_Array.txt
More file actions
50 lines (37 loc) · 1.05 KB
/
lab_session_reverseOrder_Array.txt
File metadata and controls
50 lines (37 loc) · 1.05 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
// Printing the 1D array contents in the reverse order
#include <iostream>
using namespace std;
int reverseOrder(int [], int );
int main()
{
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int size = sizeof(arr) / sizeof(int);
reverseOrder(arr, size);
return 0;
}
int reverseOrder(int b[], int n){
for(int i = n -1 ; i >= 0 ; i--){
cout << b[i] << endl;
}
return b[0];
}
-----------------------------------------------------------------------------------------------
// Create another 1D array to load the input array contents in the reverse order
int reverseOrder(int [],int [], int );
int main()
{
int arr[5] = {1, 2, 3, 4, 5};
int reverse[5];
int size = sizeof(arr) / sizeof(int);
reverseOrder(arr, reverse, size);
return 0;
}
int reverseOrder(int b[],int c[], int n){
for(int i = 0 ; i < n ; i++){
c[i] = b[n - 1 - i];
}
for(int i = 0 ; i < n ; i++){
cout << c[i] << endl;
}
return b[0];
}