Write a program that will prompt the desired search item among the user input array is found or not found by using of the following search method.
a. Linear Search
b. Binary Search
A binary search is useful only on a sorted array. Can it be assumed that the user will enter the values in numerical order? If not then go with the linear search.
#include<iostream.h>
#include<conio.h>
void find(int a, int b[50],int n)
{
int i,flag=0
for(i=0;i<=n;++i)
{
if(b[i]==a)
{
cout<<"element found at position " <<i+1;
flag=1;
}
}
if(flag==0)
cout<<"element not found";
break;
}
This is a function guess u know the main part and to enter the array,and to store necessary values.here a is the value to be searched for
b[50] is the array and
n is the no of elements in the array
I think u can make the user to input n