You are given a list of N integers and a value K. Print 1 if K exists in the given list of N integers, otherwise print −1.
#include <iostream>
using namespace std;
int main()
{
int a[50], i, n, k, flag=0;
cin >> n;
cin >> k;
for (int i = 0; i < n; i++){
cin >> a[i];
}
for (int i = 0; i < n; i++)
if (a[i] == k)
{
flag =1;}
if(flag==1){
cout << "1" << endl;
}
else
cout << "-1" << endl;
}