Array Linear search((((()))))

how to deal with -1…

Hi @abhinavssr2003_eab0717682969e5c,

    bool found = false;
    for (int i = 0; i < n; i++)
    {
        if (M == a[i])
        {
            cout<<i;
            found = true;
            break;
        }
    }
    if(found == false){
        cout<<-1;
    } 

You can just create a new variable found, that stores the state whether M is present or not.

SO basically it will get solved with bool

Yes @abhinavssr2003_eab0717682969e5c

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.