SHARE
TWEET

Untitled

a guest Feb 21st, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool check_if_number_exists(int a[], int n, int nr)
  6. {
  7.     if (n == - 1)
  8.         return false;
  9.  
  10.     if (a[n - 1] == nr)
  11.         return true;
  12.  
  13.     return check_if_number_exists(a, n - 1, nr);
  14. }
  15.  
  16. bool check_duplicates(int a[], int n)
  17. {
  18.     if (n == 1)
  19.         return false;
  20.  
  21.     if (check_if_number_exists(a, n -1, a[n - 1]))
  22.         return true;
  23.  
  24.     return check_duplicates(a, n - 1);
  25. }
  26.  
  27. int main()
  28. {
  29.     int a[] = {1, 2, 6, 3, 5};
  30.  
  31.     cout << check_duplicates(a, 5);
  32.     return 0;
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top