Dynamic Memory Allocations in Array With  Linear Search

 

#include <iostream>

using namespace std;

int main()
{
    int i,n,s,t=0;
    int *p;
    cout<<"Enter The Number Of  The Elements :";
    cin>>n;
    p=new int[n];
    cout<<"Enter The Elements :"<<endl;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
    }

    cout<<"Enter An Integer To Search ";
    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s==p[i])
        {
            cout<<"\n\n\t\tElements Found At The Position ="<<"["<<i<<"]"<<endl;
            t=1;
            break;
        }
    }
    if(t==0)
    {
        cout<<"\n\n\t\t Elements Not Found ";

    }

    return 0;
}
 

Comments

Popular posts from this blog