Array problem

Apr 4, 2013 at 11:42am
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
Apr 4, 2013 at 12:01pm
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 Apr 4, 2013 at 12:02pm
Apr 4, 2013 at 12:18pm
just helping me to do homework
Apr 4, 2013 at 12:51pm
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.
Apr 5, 2013 at 12:39pm
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 Apr 5, 2013 at 3:44pm
Apr 5, 2013 at 2:23pm
Thanks cyberdude
Topic archived. No new replies allowed.