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
What is the benefit of using const for declaring constants?
How do I use strcmp?
Explain how do you determine the length of a string value that was stored in a variable?
What is the use of bitwise operator?
What is data structure in c and its types?
Differentiate between static and dynamic modeling.
What is a macro?
What is variable declaration and definition in c?
What is the difference between null pointer and wild pointer?
How can a string be converted to a number?
i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me
What is NULL pointer?
simple program of graphics and their output display
What happens if you free a pointer twice?
Find MAXIMUM of three distinct integers using a single C statement