From 05eab2d1095e978fe02c92f272c4623fff15389d Mon Sep 17 00:00:00 2001 From: MaccxG Date: Wed, 18 Oct 2023 18:48:49 +0200 Subject: [PATCH 1/2] feat: added verify.cpp --- exercises/verify.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/verify.cpp b/exercises/verify.cpp index 2335678..a889113 100644 --- a/exercises/verify.cpp +++ b/exercises/verify.cpp @@ -15,4 +15,4 @@ int main() int N[10] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0}; return 0; -} +} \ No newline at end of file From b5ee9dbe6f102b6cfd061307387ca761ab078764 Mon Sep 17 00:00:00 2001 From: MaccxG Date: Wed, 18 Oct 2023 18:51:46 +0200 Subject: [PATCH 2/2] feat: added verify.cpp --- exercises/verify.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/exercises/verify.cpp b/exercises/verify.cpp index a889113..bac4a3d 100644 --- a/exercises/verify.cpp +++ b/exercises/verify.cpp @@ -7,12 +7,36 @@ The number 3 is [not] present in the array. */ #include + using namespace std; -int main() -{ - // placeholder +// check if the element exists in the array +bool isPresent(int *v, int n, int x) { + int i = 0; + while (i < n) { + if (v[i] == x) + return true; + i++; + } + + return false; +} + +int main() { + // init array int N[10] = {3, 4, 5, 1, 2, 3, 4, 9, 13, 0}; + // user input + int x; + cout << "Insert a number to search in the array: "; + cin >> x; + + // run check + if (isPresent(N, 10, x)) + cout << "The element is present in the array"; + else + cout << "The element is not present in the array"; + cout << endl; + return 0; } \ No newline at end of file