LINEAR_SEARCH

#include<iostream>
using namespace std;

int main()
{
    cout<<"how many elements:";
    int n;
    cin>>n;
    cout<<"enter the elements:";
    int a[20];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<"enter the elements to search:";
    int p;
    cin>>p;
    int found=0;
    int i;
    for(i=0;i<n;i++)
    {
        if(a[i]==n)
            found++;
       
    }
    if(found==1)
        cout<<"The elements found at position "<<i-1<<endl;
    else
        cout<<"the elements not exist in the array"<<endl;
       
    return 0;
}

Total Pageviews