Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

cin.ignore(80, _ _);This statement a) ignores all input b) ignores the first 80 characters in the input c) ignores all input till end-of-line d) iteration

1053


if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above

1107


In a byte, what is the maximum decimal number that you can accommodate?

1067


why we wont use '&' sing in aceesing the string using scanf

2308


Does * p ++ increment p or what it points to?

1053


c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above

1202


What is the size of empty structure in c?

1015


Is anything faster than c?

968


How can I prevent another program from modifying part of a file that I am modifying?

1006


code for find determinent of amatrix

1910


Why c language is called c?

947


What is the difference between c and python?

1101


how is the examination pattern?

1960


Is c language still used?

932


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2714