LINEAR SEARCH Program Implementation in c++
|
Download Attachment
|
/**********************************/ /*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(); }
|
|
|
|
|
Share this article
| Print |
Article read by 4877 times
|
|
|