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

What is getch c?

1300


Explain goto?

1156


State the difference between x3 and x[3].

1112


In the DOS enveronment, normal RAM that resides beyond the 1mb mark. a) expanded memory b) swapped memory c) Extended memory d) none

1203


C language questions for civil engineering

1720


How can I write a function analogous to scanf?

1183


What are the features of the c language?

1086


What is a dynamic array in c?

1159


What is the difference between void main and main in c?

1156


Explain what are the different file extensions involved when programming in c?

1110


What is integer constants?

1080


Can we change the value of #define in c?

999


What is meant by type casting?

1054


What is selection sort in c?

1095


What is use of bit field?

1300