Skip to content

Commit 4a43db6

Browse files
feat: implemented array search
1 parent f8f4676 commit 4a43db6

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

exercises/verify.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,34 @@ The number 3 is [not] present in the array.
99
#include <iostream>
1010
using namespace std;
1111

12+
bool isPresent(int* Arr, const size_t& size, const int& n);
13+
void printOutput(bool present);
14+
15+
bool isPresent(int* Arr, const size_t& size, const int& n){
16+
for(size_t i = 0; i < size ; i++){
17+
if(Arr[i] == n){ return true; } // FOUND!!
18+
}
19+
return false;
20+
}
21+
22+
void printOutput(bool present){
23+
cout << "The number is ";
24+
if(!present){ //not present
25+
cout << "not ";
26+
}
27+
cout << "present in the array." << endl;
28+
}
29+
1230
int main()
1331
{
14-
// placeholder
15-
int N[10] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0};
32+
int N[] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0};
33+
size_t arrSize = 10;
34+
int numInput;
35+
36+
cout << "Insert number: " << endl;
37+
cin >> numInput;
38+
39+
printOutput( isPresent( N , arrSize , numInput) );
1640

1741
return 0;
1842
}

0 commit comments

Comments
 (0)