Binary search in array: - c program, C/C++ Programming

Assignment Help:

Binary search in array: - C program:

Write a program in c to define binary search in array.

void main()

                {

                clrscr();

                int a[100] , ch , n;

                cout<<"enter the nit for the array : ";

                cin>>n;

                for (int i=0;i

                                {

                                cout<<"enter element "<

                                cin>>a[i];

                                }

                  Cout<< "Binary search:"

                        bsearch (a,n);

                getch();

                } //main

 

void bsearch (int a[100] , int n)

                {

                int f=0,l=n-1,m,i,ele,pos=-1;

                cout<<"enter the element to be searched : ";

                cin>>ele;

                isort(a,n);

                clrscr();

                if (a[0]

                                {

                                while (f<=l && pos=-1)

                                                {

                                                m=(f+l)/2;

                                                if (ele == a[m])

                                                                {

                                                                pos=m;

                                                                }

                                                if (ele>a[m])

                                                                f=m+1;

 

                                                if (ele

                                                                l=m-1;

                                                }

                                if (pos=-1)

                                                cout<<"elememt not found";

                                else

                                                cout<<"element found at "<

 

                                else

                                                {

                                                while (f<=l && pos=-1)

                                                                {

                                                                m=(f+l)/2;

                                                                if (ele == a[m])

                                                                                {

                                                                                pos=m;

                                                                                }

                                                                if (ele>a[m])

                                                                                l=m+1;

 

                                                                if (ele

                                                                                f=m-1;

                                                                }

 

 


Related Discussions:- Binary search in array: - c program

Pascal programming , 1. The management of a company would like to determine...

1. The management of a company would like to determine the median annual salary of its employees.Write a pascal program that display the number of employees and their median salary

Explain processing a data file, Explain Processing A Data File? Mainly ...

Explain Processing A Data File? Mainly data file applications needs that a data file be altered as it is being processed. For instance in an application involving the processin

Palindrome, A palindrome is a string that reads the same from both the ends...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Class and object, write a class player that contain attributes for the play...

write a class player that contain attributes for the player,s name,average and team

Solution, 3 . Write a ‘C’ program to accept any 3 digit integer numb...

3 . Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

Read writers problem, Readers Writers with Processes and Threads Write two ...

Readers Writers with Processes and Threads Write two programs implementing ``reader pritority readers-writers synchronization'''' on files. One program will use processes, created

What is the maximum number of constructors, Question: (a) (i) Explain...

Question: (a) (i) Explain how class members can be accessed when using objects of the class. Use a suitable example to illustrate your answer. (ii) Explain how the privat

Intro to C++ Lab Help, I have a very confusing assignment and I''m struggli...

I have a very confusing assignment and I''m struggling to find the right place to begin or how to break the problem down.

program to conduct timber structural component design, The question descri...

The question description: You are required to make a C++ program to conduct timber component (beam and column) structural design according to EC5 (all the relevant design codes

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd