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

12y 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.


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.


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.


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.


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; }


What is the use of binary?

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


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.


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.


What is the binary number for decimal 191?

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


Are binary search trees always balanced?

No, binary search trees are not always balanced. Balancing a binary search tree involves ensuring that the height difference between the left and right subtrees of each node is at most 1. Unbalanced binary search trees can lead to inefficient search and insertion operations.

Trending Questions
What are the next 3 letters in the following Sentence J F M A M J J A? I copied the folders and files from Linux bootable CD and now i want to make bootable CD from files and folder which I've copied How can i do this? What can you use to bypass a video security system and how? What should you do if you have a new home and whenever you run the washing machine and it spins and drains your kitchen sink makes a horrible gurgling noise but the contractor says it's up to code? Working and construction of ruby laser? In an older house if you have the metal pipe for the toilet without a flange in the basement can you split the pipe and add the flange to use it for a sink drain too? How is Artificial intelligence used in computer? What is the type of reasoning that is purposeful self-regulating judgment that includes interpretation analysis evaluation and influence that leaders use to solve problems? when was yes invented? How many excavator does a oiler greas on pipeline? Are the friction losses of the machine linear in induction motor electrical machines? Describe the four basic data types in c? What is the difference between scientist and technologist? What is Siemens Grey RAL 7032 color? Who invented the hydraulic excavator? How does one control Cursor speed? What is absolute and relative error? What is Charles Simonyi's contribution to computer programming? Does a current carrying conductor experience a force when kept parallel to the magnetic field? What are the three things required for HTML programming?