-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecursion.cpp
More file actions
42 lines (35 loc) · 728 Bytes
/
recursion.cpp
File metadata and controls
42 lines (35 loc) · 728 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
// This program uses recursion to check if an item is in an array
#include <iostream>
#include <iomanip>
using namespace std;
bool isMember(int [], int, int);
int main()
{
const int SIZE = 6;
int arr[SIZE] = { 10,20,30,40,50,60 };
if (isMember(arr, SIZE, 10))
{
cout << "The item is a member of the function" << endl;
}
else {
cout << "The item is NOT a member of the function" << endl;
}
return 0;
}
bool isMember(int arr[], int size, int item)
{
size--;
if (size >= 0)
{
if (arr[size] == item)
{
return true;
}
else {
isMember(arr, size, item);
}
}
else {
return false;
}
}