Wednesday, 4 November 2015

Write A Program To Linear Search Using Dynamic Array

//program for linear search

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
//By-Ghanendra Yadav
int *a,i,itm,s,flag=0;

cout<<"ENTER THE SIZE OF ARRAY : "<<endl;
cin>>s;

a=(int*)malloc(s*sizeof(int));

cout<<"ENTER THE NUMBER"<<endl;
for(i=0;i<s;i++)
{
cin>>a[i];
}

cout<<"ENTER THE NUMBER FOR SEARCHING : "<<endl;
cin>>itm;

for(i=0;i<s;i++)
{
if(a[i]==itm)
flag=1;
}

if(flag==1)
cout<<"ITEM FOUND \n";
else
cout<<"ITEM NOT FOUND \n";
}

Output:-


No comments:
Write comments

Recommended Posts × +