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
cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration
if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above
In a byte, what is the maximum decimal number that you can accommodate?
why we wont use '&' sing in aceesing the string using scanf
Does * p ++ increment p or what it points to?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
What is the size of empty structure in c?
Is anything faster than c?
How can I prevent another program from modifying part of a file that I am modifying?
code for find determinent of amatrix
Why c language is called c?
What is the difference between c and python?
how is the examination pattern?
Is c language still used?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion