Sie sind auf Seite 1von 2

***/ LINEAR SEARCH IN ARRAY /***

#include<stdio.h> #include<conio.h> void main() { int a[10],i,loc,n,x; printf("enter the no of elements"); scanf("%d",&n); printf("enter the elements"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("enter the value to search"); scanf("%d",&x); loc=-1; for(i=0;i<n;i++) { if(a[i]==x) { loc=i; break; } } if(loc==-1) printf("item not found"); else

printf("item is search at %d",loc); getch(); }

Das könnte Ihnen auch gefallen