Array problem

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
closed account (D80DSL3A)
Who's taking the programming class? You or me?
I don't recall signing up. Will I get the class credit if I do the assignment?
Last edited on
just helping me to do homework
closed account (D80DSL3A)
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.
IF IT IS THE CODE YOU WANT here it is....
Linear search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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


Last edited on
Thanks cyberdude
Topic archived. No new replies allowed.