求高人解惑 输出时不显示结果
#include <stdio.h >#define SIZE 16
int binarysearch ( int low, int high, int Array[], int value ) ;
int main ( void )
{
int i = 0;
int location;
int array [ SIZE ];
int key;
for( i=0; i< SIZE ; i++ )
{
array [ i ] = 2* i;
}
printf( " insert number you want to check\n ");
scanf(" %d ", &key );
location = binarysearch ( 0, SIZE-1, array, key );
if ( !location ) printf(" no this one\n ");
else
{
printf( "Location in the array is %d \n" , location );
}
return 0;
}
int binarysearch ( int low, int high, int Array[], int value )
{
int middle ;
while ( low <= high )
{
middle = (low + high)/2 ;
if ( value == Array [ middle ] ) return middle;
else if ( value < Array [ middle ])
{
high = middle -1;
}
else
{
low = middle +1 ;
}
}
return 0;
}