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
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 |
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 |
count the numbers between 100 and 300, that star with 2 and ends with 2
When should volatile modifier be used?
pgm to find middle element of linklist(in efficent manner)
. Write a program to get a string and to convert the 1st letter of it to uppercase
Write a program to swap two numbers without using third variable in c?
what is a function method?give example?
wat is the output int main() { char s1[]="Hello"; char s2[]="Hello"; if(s1==s2) printf("Same"); else printf("Diff"); }
What are the advantage of c language?
Why is c called c not d or e?
Is c programming hard?
Code for calculating square root without using library function, of math.h
HOW TO SWAP TWO NOS IN ONE STEP?