Linear Search Program in C++


Prev Tutorial Next Tutorial

Linear Search in C++

Linear search is also called as sequential search. Linear search is a method for finding a particular value in a list. In this searching technique you need to check every elements one by one until desired element found.

Example of Linear Search in C++

	
#include<iostream.h>
#include<conio.h>

void main()
{
int i,a[50],num,size;
clrscr();
cout<<"Enter Size of array: ";
cin>>size;
cout<<"Enter element in array: \n"<<size;
for(i=0;i<size;i++)
{
cin>>a[i];
}
cout<<"Enter element for search: ";
cin>>num;
for(i=0;i<size;i++)
{
if(a[i]==num) // if element is found
{
cout<<"\n"<<"is present at"<<position <<num <<i+1;
break;
}
}
if(i==size)
{
cout<<"\n "<<"is not found"<<num;
}
getch();
  }

Output

	
Enter Size of array: 5
Enter 5 element in array
10
6
4
12
20
Enter element for search: 4
4 is present at 3 position
binary search in c++
Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements