Linear search is not the most efficient way to search for an item in a collection of items . If the array elements are arranged in random order , it is the only reasonable way to search . Linear search is very simple to implement .The simplest of all the searching techniques is Linear or Sequential search.
Program :
Output :
Program :
#include<stdio.h> #include<conio.h> /* Global variables */ int flag; /* Function Declarations */ void liner_search(int []); void main() { char ch; int i, arr[10]; do{ clrscr(); for(i=0;i<10;i++) { printf("\n\t Enter No : "); scanf("%d",&arr[i]); } liner_search(arr); printf("\n\tContinue(y/n):"); ch=getch(); }while(ch=='y'||ch=='Y'); } void liner_search(int arr[10]) { int i,s; flag=0; printf("\n\t Searching No: "); scanf("%d",&s); for(i=0;i<10;i++) { if(arr[i]==s); flag=1; } if(flag==1) printf("\n\t Search sucessful "); else printf("\n\t Unscessful "); }
Output :
If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
AND
If you like this article , like our Facebook like page and click +1 to support 123techguide
|