If In Array
محتوى الدرس
#include <iostream>
#include <vector>
using namespace std;
/*
In Array -> In Container
In_Array({1, 2, 3, 4, 5}, 5) -> True
In_Array({1, 2, 3, 4, 5}, 6) -> False
*/
bool in_array(vector<int> arr, int target)
{
for (int i = 0; i < arr.size(); i++)
{
if (arr[i] == target)
{
return true;
}
}
return false;
}
int main()
{
cout << boolalpha;
cout << in_array({1, 2, 3, 4, 5}, 3) << endl; // 1 -> True
cout << in_array({1, 2, 3, 4, 5}, 6) << endl; // 0 -> False
return 0;
}