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

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;

                                                                }

 

 

Posted Date: 10/19/2012 3:12:07 AM | Location : United States







Related Discussions:- Binary search in array: - c program, Assignment Help, Ask Question on Binary search in array: - c program, Get Answer, Expert's Help, Binary search in array: - c program Discussions

Write discussion on Binary search in array: - c program
Your posts are moderated
Related Questions
Given a bool variable isReadable write some statements that assign true to isReadable if the file "topsecret" exists and can be read by the program and assigns false to isR

Write a C program to compute the value of a sine wave from 0 to 2P with an increment of 0.1 radians.   #include stdio.h #include math.h #define pi 3.1415927 void main() {   c

Lennie McPherson, proprietor of Lennie''''s Bail Bonds, needs to calculate the amount due for setting the bail. Lennie requires something of value as collateral, and his fee is 10%

source code for padovan string

- Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles. The user should be able to view all DVD titles in his library, add and d

Task 1 Demonstrate a Java client and server exchanging one text message in each direction. Task 2 Demonstrate a C client and server exchanging one text message in each

Goal: Design a program that computes square matrix multiplication on GPU using CUDA. Write the code in C. In particular, your implementation should obey the following requiremen

Develop Online Slot Video Game for Facebook Prepare an online slot video game for a Facebook promotion in order to draw new visits and Increase the number of "likes" of the Face

Description A long time ago in a galaxy far, far away, the country Mafghanistan had n cities and m old roads, where each road connected a pair of cities. Due to the treacherous mo