warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
#include<stdio.h>//#include<string.h>intbinsearch(intx,intv[],intn)intbinsearch(intx,...
#include <stdio.h>//#include <string.h>
int binsearch (int x,int v[],int n)
int binsearch (int x, int v[], int n) { int low,mid,high;
low = 0;
high = n-1;
mid = (low + high) / 2;
while (low <= high && x != v[mid]) {
// mid = (low + high) / 2;
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
mid = (low + high) / 2;
}
if (x == v[mid])
return mid ;
else
return -1 ;
}
void main () {
int x =7 ;
int num;
int n = 10;
int v[n]={1,2,3,4,5,6,7,8,9};
//gets(v);
num = binsearch (7,v,10) ;
printf("%d",num);
} 展开
int binsearch (int x,int v[],int n)
int binsearch (int x, int v[], int n) { int low,mid,high;
low = 0;
high = n-1;
mid = (low + high) / 2;
while (low <= high && x != v[mid]) {
// mid = (low + high) / 2;
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
mid = (low + high) / 2;
}
if (x == v[mid])
return mid ;
else
return -1 ;
}
void main () {
int x =7 ;
int num;
int n = 10;
int v[n]={1,2,3,4,5,6,7,8,9};
//gets(v);
num = binsearch (7,v,10) ;
printf("%d",num);
} 展开
2个回答
展开全部
#include <stdio.h>//#include <string.h>
//int binsearch (int x,int v[],int n)
int binsearch (int x, int v[], int n)
{
int low,mid,high;
low = 0;
high = n-1;
mid = (low + high) / 2;
while (low <= high && x != v[mid])
{
// mid = (low + high) / 2;
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
mid = (low + high) / 2;
}
if (x == v[mid])
return mid ;
else
return -1 ;
}
int main ()
{
int x =7 ;
int num;
//int n = 10;
int v[10]={1,2,3,4,5,6,7,8,9};
//gets(v);
num = binsearch (7,v,10) ;
printf("%d",num);
return 0;
}
你说的那种警告信息是因为你的变量类型用的不对或其它一些编译器的限制而引起的警告,还有,你的头文件下那个int binsearch (int x,int v[],int n)干什么写两次,并且就算你第一个是声明也因该加上分隔符号啊。
PS:不知你用的什么编译器,但我在linux下用gcc编译,我把你那个程序里第一个int binsearch(int x,int v[],int n)注释掉了,然后将v[n]改成了v[10](因为数组不能用变量定义大小,不然编译回报错),还有我这编译器编译时主函数必须int类型,所也我把你那个函数返回类型也该了下,不然我这儿编译不通过,以上修改之后程序能正常运行。 另外你写程序格式尽量整齐一点,不然看着累!!!
//int binsearch (int x,int v[],int n)
int binsearch (int x, int v[], int n)
{
int low,mid,high;
low = 0;
high = n-1;
mid = (low + high) / 2;
while (low <= high && x != v[mid])
{
// mid = (low + high) / 2;
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
mid = (low + high) / 2;
}
if (x == v[mid])
return mid ;
else
return -1 ;
}
int main ()
{
int x =7 ;
int num;
//int n = 10;
int v[10]={1,2,3,4,5,6,7,8,9};
//gets(v);
num = binsearch (7,v,10) ;
printf("%d",num);
return 0;
}
你说的那种警告信息是因为你的变量类型用的不对或其它一些编译器的限制而引起的警告,还有,你的头文件下那个int binsearch (int x,int v[],int n)干什么写两次,并且就算你第一个是声明也因该加上分隔符号啊。
PS:不知你用的什么编译器,但我在linux下用gcc编译,我把你那个程序里第一个int binsearch(int x,int v[],int n)注释掉了,然后将v[n]改成了v[10](因为数组不能用变量定义大小,不然编译回报错),还有我这编译器编译时主函数必须int类型,所也我把你那个函数返回类型也该了下,不然我这儿编译不通过,以上修改之后程序能正常运行。 另外你写程序格式尽量整齐一点,不然看着累!!!
追问
那个格式是复制到百度除了问题 注释是因为调试的时候用的可以去掉 大概问题是返回值跟形参类型不同 编译器差别还没搞懂 不过还是谢谢了 我用的是vc++ 6.0 选错满意答案了 尴尬
展开全部
#include <stdio.h>//#include <string.h>
int binsearch (int x,int v[],int n)
int binsearch (int x, int v[], int n) { int low,mid,high;
low = 0;
high = n-1;
mid = (low + high) / 2;
while (low <= high && x != v[mid]) {
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
mid = (low + high) / 2;
}
if (x == v[mid])
return mid ;
else
return -1 ;
}
void main ()
{
int x =7 ;
int num;
int n = 10;
int v[n]={1,2,3,4,5,6,7,8,9};
num = binsearch (7,v,10) ;
printf("%d",num);
}
int binsearch (int x,int v[],int n)
int binsearch (int x, int v[], int n) { int low,mid,high;
low = 0;
high = n-1;
mid = (low + high) / 2;
while (low <= high && x != v[mid]) {
if (x < v[mid])
high = mid - 1;
else
low = mid + 1;
mid = (low + high) / 2;
}
if (x == v[mid])
return mid ;
else
return -1 ;
}
void main ()
{
int x =7 ;
int num;
int n = 10;
int v[n]={1,2,3,4,5,6,7,8,9};
num = binsearch (7,v,10) ;
printf("%d",num);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询