This document was uploaded by user and they confirmed that they have the permission to share
it. If you are author or own the copyright of this book, please report to us by using this DMCA
report form. Report DMCA
Linear Search #include #include int search(int a[], int k, int si){ int i=0; while(k!=a[i] && i<si ){ i++; } if(i<si) return i; else return -1; } void main() { clrscr(); const int s=5; int a[s]={3,5,1,4,2}; int key,element; cout<<"\nEnter the key: "; cin>>key; element=search(a,key,s); if(element!=-1) cout<<"\nKey found at location ["<<element<<"]" ; else cout<<"\nKey was not found"; getch(); }
Click the link below to see more examples URL: http://ravianeducation.blogspot.com E-Mail: [email protected] Farhan: 03008855006