c语言题目,在线等答案。
#include<stdio.h>#defineN10main(){intk,i;inttable[N]={0,2,4,6,8,10,12,14,16,18};intmi...
#include<stdio.h>
#define N 10
main()
{
int k,i;
int table[N]={0,2,4,6,8,10,12,14,16,18};
int mid,low=0,high=N-1;
int flag=0;
printf("input your number:");
scanf("%d",&k);
while(!flag && 1)
{
mid=(low+high)/2;
if(k==table[mid])
flag=1;
else if(k<table[mid])
hig=mid-1;
else
low=mid+1;
}
if(flag==1)
printf("%d in table[%d]\n",k,mid);
else
printf("can't find the number%d.\n",k);
}
哪有问题,怎么改? 展开
#define N 10
main()
{
int k,i;
int table[N]={0,2,4,6,8,10,12,14,16,18};
int mid,low=0,high=N-1;
int flag=0;
printf("input your number:");
scanf("%d",&k);
while(!flag && 1)
{
mid=(low+high)/2;
if(k==table[mid])
flag=1;
else if(k<table[mid])
hig=mid-1;
else
low=mid+1;
}
if(flag==1)
printf("%d in table[%d]\n",k,mid);
else
printf("can't find the number%d.\n",k);
}
哪有问题,怎么改? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询