nvnnaidenov

Zad60

Oct 19th, 2021
777
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void ReadArr(int, int[]);
  6. bool IsContainsX(int, int, int[]);
  7.  
  8. int main()
  9. {
  10.     bool contains;
  11.     int n;
  12.     int x;
  13.     int arr[20];
  14.  
  15.     cout << "n = ";
  16.     cin >> n;
  17.     if(!cin)
  18.     {
  19.         cout << "Error, bad input!" << endl;
  20.         return 1;
  21.     }
  22.     if(n <= 0 || n > 20)
  23.     {
  24.         cout << "Error, incorect input!" << endl;
  25.         return 1;
  26.     }
  27.  
  28.     cout << "x = ";
  29.     cin >> x;
  30.     if(!cin)
  31.     {
  32.         cout << "Error, bad input!" << endl;
  33.         return 1;
  34.     }
  35.  
  36.     contains = false;
  37.  
  38.     ReadArr(n, arr);
  39.  
  40.     contains = IsContainsX(n, x, arr);
  41.  
  42.     cout << contains;
  43. }
  44.  
  45. void ReadArr(int n, int arr[])
  46. {
  47.     for(int i = 0; i <= n - 1; i++)
  48.     {
  49.         cout << "[" << i << "] = ";
  50.         cin >> arr[i];
  51.     }
  52. }
  53.  
  54. bool IsContainsX(int n, int x, int arr[])
  55. {
  56.     int i = 0;
  57.     while(arr[i] != x && i <= n - 1)
  58.     {
  59.         i++;
  60.     }
  61.     return arr[i] == x;
  62. }
RAW Paste Data