Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- bool isMemberOf(const int* arr, const int arg, const int& length, int currIndex = 0) {
- if (arr[0] == arg)
- return true;
- if (currIndex >= length)
- return false;
- return isMemberOf(arr + 1, arg, length, currIndex + 1);
- }
- bool isAllEven(const int* arr, const int& len, int currNumber = 0) {
- if (currNumber == len)
- return true;
- if (isMemberOf(arr, 2 * currNumber, len))
- return true && isAllEven(arr, len, currNumber + 1);
- return false;
- }
- int main() {
- int arr[5] = { 0, 2, 4, 6, 9 };
- std::cout << isAllEven(arr, 5);
- arr[4] = 8;
- std::cout << isAllEven(arr, 5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement