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
why wipro wase
What is sizeof int?
Why do we need functions in c?
Explain about the constants which help in debugging?
Is stack a keyword in c?
Differentiate between declaring a variable and defining a variable?
How was c created?
How is pointer initialized in c?
What is the best organizational structure?
Write a program to print "hello world" without using a semicolon?
What is a static function in c?
Is anything faster than c?
what is the diffrenet bettwen HTTP and internet protocol
Why are algorithms important in c program?
One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.