#include <bits/stdc++.h>
#define fast std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define ll long long
#define usll unsigned long long
#define p push_back
#define b begin()
#define e end()
#define so sort
using namespace std;
int find(vector<int> &v, int start, int end, int target)
{
int mid = (v[start] + v[end - 1]) / 2;
if(mid > target)
{
return find(v, start, mid, target);
} else if(mid < target)
{
return find(v, mid, end, target);
} else
{
return 1;
}
return 0;
}
int main()
{
fast;
int n, x;
cin >> n >> x;
vector<int> v;
for(int i = 0; i < n; i++)
{
int a;
cin >> a;
v.p(a);
}
cout << find(v, 0, n, x);
}
Yêu cầu: Viết chương trình kiểm tra một sô nguyên X có trong mảng A gồm N phần tử hay không, nếu có in ra 1, ngược lại 0.
Em làm code như trên nhưng khi chạy chương trình nhập ví dụ vào thì bị lỗi
####.exe has stopped working.
Mọi người giúp em chỉ ra em sai chỗ nào với ạ, em xin cảm ơn mọi người nhiều ạ
Đây là test case ạ:
5 5
2 5 7 12 15