write an algorithm which can find the largest number among
the given list using binary search ...............
this was asked in the interview

Answer Posted / vishnu948923

void main()
{
int a[10],i,flag,mid,low=0,high=9,num;
printf("enter how many elements");
scanf("%d",&num);

for(i=0;i<=9;i++)
scanf("%d",&a[i]);

for(mid=(low+high)/2; low<=high;mid=(low+high)/2)
{
if(a[mid]==num)
{
printf("Element position %d",mid);
flag=0;
break
}
if(a[mid]>num)
high=mid-1;
else
low=mid+1;
}
if(flag)
printf("element not present");
}


Is This Answer Correct ?    16 Yes 14 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you call a function, given its name as a string?

689


4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.

1700


What are qualifiers in c?

548


What is a node in c?

524


What are c identifiers?

606






hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...

1408


An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array

661


Why is event driven programming or procedural programming, better within specific scenario?

1924


What are the advantages and disadvantages of a heap?

679


How can you allocate arrays or structures bigger than 64K?

654


Why do we use header files in c?

556


How can you find out how much memory is available?

594


What is data structure in c language?

572


What is a file descriptor in c?

539


What is the heap?

641