LINEAR SEARCH Program Implementation in c++
/**********************************/ /*PROGRAM TO PREFORM LINEAR SEARCH*/ /**********************************/
#include < stdio.h> #include < conio.h>
void main() { int a[10],n,i,item,loc; clrscr(); printf("Enter the size of array: "); scanf("%d",&n); printf("\nEnter the elements of array:\n"); for(i=0;i { scanf("%d",&a[i]); } printf("\nEnter the item tobe searched: "); scanf("%d",&item);
a[n]=item; loc=0; while(a[loc]!=item) { loc=loc+1; } if(loc==n) { printf("\nItem %d is not present in the array",item); } else { printf("\nItem %d is present at %d location in the array",item,loc+1); } getch(); }
http://
http://
Contributed by:
Rohit kakria
I am software developer
Resourse address on xpode.com
http://www.xpode.com/Print.aspx?Articleid=345
Click here to go on website
|