Linear search

 


Linear Search





OURSHOPKEEPER






#include <iostream>
using namespace std;
int main()
{
    int a[50], i, j, n, elem, flag = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cout << a[i]<<" ";
    }
    cout << "Enter the element to be found: "<<endl;
    cin >> elem;
    for (int i = 1; i <=n; i++)
        if (elem == a[i])
        {
            flag=i;
        }
    if (flag > 0)
    {
        cout << "Ethe element found at: " << flag<<endl;
    }

    else
    {
        cout << "Element is not found!!! "<<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