Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

Answers were Sorted based on User's Feedback



write an algorithm which can find the largest number among the given list using binary search .......

Answer / shruti

In binary search , we have sorted array.

Hence the last number in the array is the largest number
among the given list.. :-)


Ur interviewer has to be very intelligent.. :-)
Gud ques though..

Is This Answer Correct ?    18 Yes 5 No

write an algorithm which can find the largest number among the given list using binary search .......

Answer / 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

More C Interview Questions

What is action and transformation in spark?

0 Answers  


What kind of structure is a house?

0 Answers  


Write a C program in Fibonacci series.

0 Answers   iNautix,


What is #pragma directive?how it is used in the program? what is its advantages and disadvantages?

2 Answers  


In which mode we open the file for read,write and append also in c ? a)W b)w+ c)r+ d)a

2 Answers   BitWise,






The difference between printf and fprintf is ?

0 Answers   Baan Infotech,


What is the scope of static variable in c?

0 Answers  


main() { enum{red,green,blue=6,white}; pf("%d%d%d%d", red,green,blue,white); return 0; } a)0 1 6 2 b)0 1 6 7 c)Compilation error d)None of the above

6 Answers  


Write a program to check whether a number is prime or not using c?

0 Answers  


Between macros and functions,which is better to use and why?

0 Answers  


int a=1,b=2,c=3; printf("%d,%d",a,b,c); What is the output?

14 Answers   Verifone,


How can I find out how much memory is available?

1 Answers   Persistent,






Categories