cpp c++ program for linear search

#include<iostream>
using namespace std;
int main()
{
    int arr[10], i, num, location;
    cout<<"Enter 10 Numbers: ";
    for(i=0; i<10; i++)
        cin>>arr[i];
    cout<<"\nEnter a Number to Search: ";
    cin>>num;
    for(i=0; i<10; i++)
    {
        if(arr[i]==num)
        {
            Location = i;
            break;
        }
    }
    cout<<"\nFound at location : "<<location;
    cout<<endl;
    return 0;
}

Comments

Popular posts from this blog