Friday, 21 April 2017

Linear and Binary Search /Session VIII

1. Searching an Array


Write a C program to search for an element ‘a’ in the array. (Linear Search)
Input Format:
Input consists of n+2 integers. The first integer corresponds to ‘n’ , the size of the array. The next ‘n’ integers correspond to the elements in the array. The last integer corresponds to ‘a’, the element to be searched.
Assume that the maximum size of the array is 20.
Output Format:
Refer  sample output for details.

click Link below for code:
 http://geekclues.blogspot.in/p/1.Searching an Array. html





2.Implementation of Binary Search

Write a C program to implement Binary Search Algorithm.

Include a function

int BinarySearch (int, int, int *, int x) --- The 1st parameter is the lower limit of the list or array, the 2nd parameter is the upper limit of the list or array, the third parameter is a pointer to the array and the fourth parameter is the search element.

Please note that the index of the search element is returned by the function. If the search element is not present in the array, -1 is returned.

Assume that the maximum size of the array is 10 . Please note that if a is the array, then a[0] is in position 0, a[1] is in position 1 ...


click Link below for code:




No comments:

Post a Comment