Check Number
Send Feedback
Line 1 : An Integer N i.e. size of array
Line 2 : N integers which are elements of the array, separated by spaces
Line 3 : Integer x
'true' or 'false'
1 <= N <= 10^3
3
9 8 10
8
true
3
9 8 10
2
false
SOLUTION:-
#include<iostream>
using namespace std;
bool checkNumber(int input[], int size, int x) {
/* Don't write main().
Don't read input, it is passed as function argument.
Return output and don't print it.
Taking input and printing output is handled automatically.
*/
if(size==0)
return false;
else{
if(input[size]==x)
return true;
else{
checkNumber(input,size-1,x);
}
}
}
int main(){
int n;
cin >> n;
int *input = new int[n];
for(int i = 0; i < n; i++) {
cin >> input[i];
}
int x;
cin >> x;
if(checkNumber(input, n, x)) {
cout << "true" << endl;
}
else {
cout << "false" << endl;
}
}
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon