#include “iostream.h”
#include “time.h”
#include “stdlib.h”
void print(int a[])
{
for(int i=0; i<10; i++)
cout<<a[i]<<” “;
cout<<endl;
}
void main()
{
int a[10];
srand(time(NULL));
for(int i=0; i<10; i++)
a[i] = rand() % 101;
print(a);
int min, t, j;
for(i=0; i<9; i++)
{
min = i;
for(j=i+1; j<9; j++)
if(a[min]>a[j])
min = j;
t = a[min];
a[min] = a[i];
a[i] = t;
}
print(a);
int n;
cout<<“please input a number: “;
cin>>n;
int low=0, high=9, mid;
while(low<=high)
{
mid=(low+high)/2;
if(n==a[mid])
break;
else if(n<a[mid])
high = mid – 1;
else
low = mid + 1;
}
cout<<mid<<endl;
}