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.

 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.







OURSHOPKEEPER









#include <iostream>
using namespace std;
int main()
{
    int a[50], inkflag=0;
    cin >> n;
    cin >> k;
    for (int i = 0i < ni++){
        cin >> a[i];
    }
    for (int i = 0i < ni++)
        if (a[i] == k)
        {  
            flag =1;}
            if(flag==1){
            cout << "1" << endl;
            }
        else
            cout << "-1" << endl;
}




    


Click on the above button to download the code.



Post a Comment

If you have furthur QUERIES please let us know

Previous Post Next Post