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 does the c in ctime mean?
Explain high-order and low-order bytes.
shorting algorithmS
what are the facialities provided by you after the selection of the student.
cavium networks written test pattern ..
What is c language & why it is used?
What are the types of arrays in c?
Where is volatile variable stored?
What are the functions to open and close the file in c language?
What is integer constants?
What is the purpose of & in scanf?
Is printf a keyword?
A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.
Explain how do you list files in a directory?
What is the default value of local and global variables in c?