请高手帮忙解答一道c语言题
#include<stdio.h>intfun(inta[],intm){intlow=0,high=9,mid;while(low<=high){mid=(low<=h...
#include<stdio.h>
int fun(int a[],int m)
{int low=0,high=9,mid;
while(low<=high)
{mid=(low<=high)/2;
{if(m<a[mid])
high=mid-1;
else if(m>a[mid])low=mid+1;
else return(mid);}return(-1);}
main()
{int i,k,m,a[10]={-3,4,7,9,13,45,67,89,100,180};
for(i=0;i<10;i++)printf("%d ",a[i]);
printf("\nenter m:");scanf("%d",&m);
k=fun(a,m);
if(k>=0)printf("m=%d,index=%d\n",m,k);
else printf("not be found\n");}
哪里出了错?老是提示说有错误,没办法运行 展开
int fun(int a[],int m)
{int low=0,high=9,mid;
while(low<=high)
{mid=(low<=high)/2;
{if(m<a[mid])
high=mid-1;
else if(m>a[mid])low=mid+1;
else return(mid);}return(-1);}
main()
{int i,k,m,a[10]={-3,4,7,9,13,45,67,89,100,180};
for(i=0;i<10;i++)printf("%d ",a[i]);
printf("\nenter m:");scanf("%d",&m);
k=fun(a,m);
if(k>=0)printf("m=%d,index=%d\n",m,k);
else printf("not be found\n");}
哪里出了错?老是提示说有错误,没办法运行 展开
展开全部
是小问题。我帮你改了下,可以了
#include<stdio.h>
int fun(int a[],int m)
{
int low=0,high=9,mid;
while(low<=high)
{
mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
else if(m>a[mid])
low=mid+1;
else return(mid);
}
return (-1);
}
main()
{
int i,k,m,a[10]={-3,4,7,9,13,45,67,89,100,180};
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\nenter m:");
scanf("%d",&m);
k=fun(a,m);
if(k>=0)
printf("m=%d,index=%d\n",m,k);
else
printf("not be found\n");
}
#include<stdio.h>
int fun(int a[],int m)
{
int low=0,high=9,mid;
while(low<=high)
{
mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
else if(m>a[mid])
low=mid+1;
else return(mid);
}
return (-1);
}
main()
{
int i,k,m,a[10]={-3,4,7,9,13,45,67,89,100,180};
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\nenter m:");
scanf("%d",&m);
k=fun(a,m);
if(k>=0)
printf("m=%d,index=%d\n",m,k);
else
printf("not be found\n");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询