C++ program for Linear search .

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#define N 5
void ls(){
int list[N],item,i;
clrscr();
cout<<"Enter Element of list"<<endl;
for(i=0; i<N; i++){
cout<<"Enter "<<i+1<<" Element of List Array = ";
cin>>list[i];
}
cout<<"Enter Element to Search = "<<endl;
cin>>item;
for(i=0; i<N; i++){
if(item==list[i]){
cout<<item<<" Item is Found at "<<i<<" Index and "<<i+1<<" Position\n Search Successful"<<endl;
getch();
exit(0);
}}
cout<<item<<" Item not Found\n Search Unsuccessful "<<endl;
return;
}
void main(){
clrscr();
cout<<"linear Search"<<endl;
ls();
getch();
}

No comments:

Post a Comment