answersLogoWhite

0

#include <iostream>

#include <conio.h>

int linearSearch( const int array[], int length, int value);

int main()

{

const int arraySize = 100;

int a[arraySize];

int element;

for( int i = 0; i < arraySize; i++)

{

a[i] = 2 * i;

}

element = linearSearch( a, arraySize, 10);

if( element != -1 )

cout << "Found value in element " << element << endl;

else

cout << "Value not found." << endl;

getch();

return 0;

}

int linearSearch( const int array[], int length, int value)

{

if(length==0) return -1;

else if (array[length-1]==value) return length-1;

else return urch( array, length-1, value);

}

it is in c++ language ,u can change it to c by including stdio.h ,printf & scanf.....i think it wud be beneficial

have a look their too. similar program like that and easy understanding

http://fahad-cprogramming.blogspot.com/2014/02/linear-search-program-in-c-using.html

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What is the advantage of the binary search method?

It gets you to the answer with fewer steps.


Is it possible for Breadth-First Search (BFS) to be implemented recursively"?

Yes, Breadth-First Search (BFS) can be implemented recursively, but it is not the most efficient method compared to using a queue-based iterative approach.


What is the method to find the height of a binary search tree in Java?

To find the height of a binary search tree in Java, you can use a recursive method that calculates the height of the left and right subtrees and returns the maximum height. This can be implemented by defining a method that takes the root node of the tree as input and recursively calculates the height of the tree.


How do you get principal varivation from iterative deepening search?

You will get principal variation from iterative deepening search using sequential moves within the framework. It is important to note that this may slow down the search due to space requirements.&Ecirc;


What assumption about the list is made when binary search is conducted?

Binary search requires that the list be in search key order.


How can you merge two binary search trees into a single binary search tree?

To merge two binary search trees into a single binary search tree, you can perform an in-order traversal on each tree to extract their elements, combine the elements into a single sorted list, and then construct a new binary search tree from the sorted list. This process ensures that the resulting tree maintains the binary search tree property.


What is the use of binary?

Binary trees are commonly used to implement binary search tree and binary heaps.


Write an iterative function to search an element in a binary search tree?

_node* search (_node* head, _key key) { _node* node; for (node=head; node != NULL;;) { if (key == node-&gt;key) return node; else if (key &lt; node.&gt;key) node = node-&gt;left; else node = node-&gt;right; } return node; }


A binary search of an orderd set of elements in an array or a sequential search of the elements.Which one is faster?

A binary search is much faster.


What is the binary number for decimal 191?

It is 10111111 in binary. Try a search for '191 to binary'.


Items that are not suitable for a binary search?

The only items suitable for a binary search are those which are in a sorted order.


Does binary tree and binary search tree same?

no they are not same