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 a structure and why it is used?
Write a program to check palindrome number in c programming?
Is multithreading possible in c?
what is the difference between 123 and 0123 in c?
How can you tell whether two strings are the same?
in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.
What is assignment operator?
What is the use of typedef in c?
What is the process to create increment and decrement stamen in c?
explain what are pointers?
Why dont c comments nest?
In c programming, explain how do you insert quote characters (? And ?) Into the output screen?
Explain how can I make sure that my program is the only one accessing a file?
Which built-in library function can be used to match a patter from the string?
What are the preprocessor categories?