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

why wipro wase

1834


What is sizeof int?

641


Why do we need functions in c?

565


Explain about the constants which help in debugging?

858


Is stack a keyword in c?

640






Differentiate between declaring a variable and defining a variable?

612


How was c created?

591


How is pointer initialized in c?

589


What is the best organizational structure?

644


Write a program to print "hello world" without using a semicolon?

600


What is a static function in c?

626


Is anything faster than c?

589


what is the diffrenet bettwen HTTP and internet protocol

1396


Why are algorithms important in c program?

625


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.

2162