In: Computer Science
Write a boolean function named isMember that takes two
arguments: an array of type
char and a value. It should return true if the value is found in
the array, or false if the
value is not found in the array.
PLEASE WRITE FULL PROGRAM IN C++ AND USE RECURSION AND DO NOT USE LOOPS
#include<iostream>
using namespace std;
bool isMember(char arr[],int n,char ch)
{
if(arr[n]==ch)
//base condition.
return true;
if(arr[n]!=ch&&n<=0) //base
condition
return false;
return isMember(arr,n-1,ch);
}
int main()
{
char
arr[]={'a','b','c','d'};
int n=4;
char ch1='a';
char ch2='e';
if(isMember(arr,n-1,ch1))
cout<<"value:"<<ch1<< " founded\n";
else
cout<<"value:"<<ch1<<" NOT found\n";
if(isMember(arr,n-1,ch2))
cout<<"value:"<<ch2<< " founded!!!!\n";
else
cout<<"value:"<<ch2<<" NOT found\n";
}
Output: