数组求最大值跟下标问题,编译不通过,不知道怎样修改
编一函数,计算有50个元素的一维实数组中最大值的位置,main定义为y[50],y[i]=600*sin(y*0.16)错误如下
Error E:\TURBOC2\C.C 28: Expression syntax in function main
Warning E:\TURBOC2\C.C 29: Possible use of 'max_1' before definition in funct
Warning E:\TURBOC2\C.C 30: Possible use of 'max_1' before definition in funct
程序如下
double vmax(double *d,int n)
{
int i,t=0;
double max_2=d[0],max_3;
if (n<0)
{return 0;
}
for(i=1;i<n;i++)
{max_3=max_2;
if (max_3<d[i])
{t=i;
max_2=d[i];
}
}
return(t);
}
main()
{
double y[50],max_1;
int j;
for(j=0;j<50;j++)
{
y[j]=600*sin(j*0.16);
}
max_1=double vmax(double y,int j);
printf("Max Number is %f",y[max_1]);
printf("Number is %f",max_1);
}
----------------解决方案--------------------------------------------------------
/*****************************************************************
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http://yzfy.org **
*****************************************************************/
double vmax(double *d,int n)
{
int i,t=0;
double max_2=d[0],max_3;
if (n<0)
{
return 0;
}
for (i=1;i<n;i++)
{
max_3=max_2;
if (max_3<d[i])
{
t=i;
max_2=d[i];
}
}
return(t);
}
main()
{
double y[50],max_1;
int j;
for (j=0;j<50;j++)
{
y[j]=600*sin(j*0.16);
}
max_1=double vmax(double y,int j);
printf("Max Number is %f",y[max_1]);
printf("Number is %f",max_1);
}
** HighlightCodeV3.0 software by yzfy(雨中飞燕) http://yzfy.org **
*****************************************************************/
double vmax(double *d,int n)
{
int i,t=0;
double max_2=d[0],max_3;
if (n<0)
{
return 0;
}
for (i=1;i<n;i++)
{
max_3=max_2;
if (max_3<d[i])
{
t=i;
max_2=d[i];
}
}
return(t);
}
main()
{
double y[50],max_1;
int j;
for (j=0;j<50;j++)
{
y[j]=600*sin(j*0.16);
}
max_1=double vmax(double y,int j);
printf("Max Number is %f",y[max_1]);
printf("Number is %f",max_1);
}
Orz
[color=white]
----------------解决方案--------------------------------------------------------
max_1=double vmax(double y,int j);
这是什么意思???
[color=white]
----------------解决方案--------------------------------------------------------
我基础太差劲,不知如何正确调用
----------------解决方案--------------------------------------------------------
调用函数的声明
----------------解决方案--------------------------------------------------------