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 getch c?
Explain goto?
State the difference between x3 and x[3].
In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none
C language questions for civil engineering
How can I write a function analogous to scanf?
What are the features of the c language?
What is a dynamic array in c?
What is the difference between void main and main in c?
Explain what are the different file extensions involved when programming in c?
What is integer constants?
Can we change the value of #define in c?
What is meant by type casting?
What is selection sort in c?
What is use of bit field?