#include<iostream>
#include<conio.h>
using namespace std;
int search(int *a,int num,int lenA){
int low=0,high=lenA;
while(low<=high){
int mid=(low+high)/2;
if(a[mid]>num)
high=mid-1;
else if(a[mid]<num)
low=mid+1;
else
return mid;
}
return 0;
}
void main(){
int a[10]={1, 3, 5, 6, 7, 8, 9, 10 ,12 ,13};
cout<<search(a,10,10)<<endl;
system("pause");
}
#include<conio.h>
using namespace std;
int search(int *a,int num,int lenA){
int low=0,high=lenA;
while(low<=high){
int mid=(low+high)/2;
if(a[mid]>num)
high=mid-1;
else if(a[mid]<num)
low=mid+1;
else
return mid;
}
return 0;
}
void main(){
int a[10]={1, 3, 5, 6, 7, 8, 9, 10 ,12 ,13};
cout<<search(a,10,10)<<endl;
system("pause");
}