实现一维数组的遍历输出,要求用五种不同的语句输出五次。
#include <stdio.h>
#define N 10
void main(void)
{
int a[N] = {-2, -1, 0, 1, 3, 4, 7, 9, 13, 17};
int i,low=0,high=N-1,mid,ret=-1;
int key;
//输入数据
scanf("%d",&key);
while(low <= high)
{
mid = low + (high-low)/2;
if(a[mid] == key)
{ret=mid;break;}
else if(a[mid] > key)
{high=mid-1;continue;}
else
{low=mid+1;continue;}
}
printf("%d ",ret);
}