include iostream using namespace std union point int decimal double _f

 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;
union point {
int decimal;
double _float;
void init() {
cin >> _float;
if ((int) _float == _float) {
decimal = (int) _float;
}
}
double get() {
if (_float != NULL) return _float;
return decimal;
}
};
struct points {
point value;
};
int main() {
size_t n;
printf("Enter the size of size of array:");
cin >> n;
struct points _points[n];
double query;
for (int i = 0; i < n; ++i) {
cout << "Enter value" << endl;
_points[i].value.init();
}
cout << "Entered array:" << endl;
for (int i = 0; i < n; ++i) {
cout << i << " - " << _points[i].value.get() << endl;
}
cout << "Enter what do you want search:" << endl;
cin >> query;
for (int i = 0; i < n; ++i) {
if ((int) query == query) {
if ((int)_points[i].value.get() == query) {
cout << "Point with value = " << query << " found." << endl;
cout << i << " - " << "value: " << _points[i].value.get() << endl << endl;
}
} else {
if (_points[i].value.get() == query) {
cout << "Point with value = " << query << " found." << endl;
cout << i << " - " << "value: " << _points[i].value.get() << endl << endl;
}
}
}
}