-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ35.cpp
More file actions
44 lines (28 loc) · 781 Bytes
/
Q35.cpp
File metadata and controls
44 lines (28 loc) · 781 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
42
43
44
// 34. Access and print the first and last element of the array arr = [10, 20, 30, 40, 50]. Output:[10,50]
#include <iostream>
using namespace std;
int main() {
int arr[] = {10, 20, 30, 40, 50};
cout << "[" << arr[0] << ", " << arr[4] << "]" << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int arr[] = {10, 20, 30, 40, 50};
cout << "[" << arr[0] << ", " << arr[sizeof(arr)/sizeof(arr[0]) - 1] << "]" << endl;
return 0;
}
#include <iostream>
using namespace std;
int main() {
int arr[] = {10, 20, 30, 40, 50};
int n = sizeof(arr) / sizeof(arr[0]);
for (int i = 0; i < n; i++) {
if (i == 0 || i == n - 1) {
cout <<arr[i]<<" ";
}
}
cout << endl;
return 0;
}