Commit 6d3c86ad authored by Artak Yenokyan's avatar Artak Yenokyan

Merge branch 'Bbranch7.33' into 'master'

michael.davityan:exercise_07_33v2

See merge request bpcarm/trainings2017!1441
parents 3af8a45d 91ca67ff
progname=exercise_07_33
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1 test2
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
184
87
178
116
194
136
187
93
50
22
163
28
91
60
164
127
141
27
173
137
12
169
168
30
183
131
63
124
68
136
130
3
23
59
70
168
194
57
12
43
30
174
22
120
185
138
199
125
116
171
14
127
92
181
157
74
63
171
197
82
106
126
85
128
137
106
47
130
114
58
125
96
183
146
15
168
35
165
44
151
88
9
77
179
189
185
4
52
155
200
133
61
77
169
140
13
27
187
95
140
77
184
87
178
116
194
136
187
93
50
22
163
28
91
60
164
127
141
27
173
137
12
169
168
30
183
131
63
124
68
136
130
3
23
59
70
168
194
57
12
43
30
174
22
120
185
138
199
125
116
171
14
127
92
181
157
74
63
171
197
82
106
126
85
128
137
106
47
130
114
58
125
96
183
146
15
168
35
165
44
151
88
9
77
179
189
185
4
52
155
200
133
61
77
169
140
13
27
187
95
140
111
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <cstdlib>
int
recursiveLinearSearch(const int integersArray[], const size_t sizeOfArray, const int searchKey,
const size_t firstIdx = 0)
{
if (integersArray[firstIdx] == searchKey) {
return firstIdx;
}
if (firstIdx == sizeOfArray) {
return -1;
}
return recursiveLinearSearch(integersArray, sizeOfArray, searchKey, firstIdx + 1);
}
int
main()
{
const size_t ARRAY_SIZE = 100;
int integersArray[ARRAY_SIZE];
if (::isatty(STDIN_FILENO)) {
std::cout << "Insert array elements\n";
}
for (size_t index = 0; index < ARRAY_SIZE; ++index) {
if (::isatty(STDIN_FILENO)) {
std::cout << "element "<< index + 1 << ": ";
}
std::cin >> integersArray[index];
}
if (::isatty(STDIN_FILENO)) {
std::cout << "Enter integer search key: ";
}
int searchKey;
std::cin >> searchKey;
const int elementIdx = recursiveLinearSearch(integersArray, ARRAY_SIZE, searchKey);
if (elementIdx != -1) {
std::cout << "Found value in element " << elementIdx + 1 << "\n";
} else {
std::cout << "Value not found" << std::endl;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment