Linear search

Linear search :-
          Linear search is the simplest search algorithm; it is a special case of brute-force search. Its worst case cost is proportional to the number of elements in the list; and so is its expected cost
Source code is available here 

#include "stdafx.h"  // Header file for MS VS
#include <iostream>  // Some compiler used < iostream.h>
#include <conio.h>  // header file

using namespace std ;
int main()
{
int a[10] = {9,8,7,6,5,4,3,2,1,0} ;
int input ;
cout << "Enter your no. that you wanna search(0 - 9) : ";
cin >> input ;
for (int i = 0 ; i <= 10 ; i ++)
{
if (a[i] == input)
cout << i ;
}
if (a[10] != input)
cout << "Your enterd no. is not found." ;
_getch() ;
return 0 ;
}
Next PostNewer Post Previous PostOlder Post Home

0 comments:

Post a Comment