Advertisement
Stoycho_KK

задача от семинар

Jan 9th, 2021 (edited)
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. bool isMemberOf(const int* arr, const int arg, const int& length, int currIndex = 0) {
  4.     if (arr[0] == arg)
  5.         return true;
  6.  
  7.     if (currIndex >= length)
  8.         return false;
  9.  
  10.     return isMemberOf(arr + 1, arg, length, currIndex + 1);
  11. }
  12.  
  13. bool isAllEven(const int* arr, const int& len, int currNumber = 0) {
  14.     if (currNumber == len)
  15.         return true;
  16.  
  17.     if (isMemberOf(arr, 2 * currNumber, len))
  18.         return true && isAllEven(arr, len, currNumber + 1);
  19.  
  20.     return false;
  21. }
  22.  
  23. int main() {
  24.     int arr[5] = { 0, 2, 4, 6, 9 };
  25.     std::cout << isAllEven(arr, 5);
  26.     arr[4] = 8;
  27.     std::cout << isAllEven(arr, 5);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement