这里哪错了

qq_45622459 2019-09-08 07:59:47
#include <stdio.h> #include <stdlib.h> int main() { double a[10],max; void fun(double b[],double *max,int *index,int m); int n,i,index; scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf",(a+i)); fun(a,&max,&index,n); printf("%5d\n%5d",max,index); } void fun(double b[],double *max,int *index,int m) { int i; for(i=0;i<m;i++) if(*max<=b[i]) { *index=i; *max=b[i]; } }
...全文
181 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2019-09-09
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>

int main()
{
double a[10],max;
void fun(double b[],double *max,int *index,int m);
int n,i,index;

scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf",(a+i));
fun(a,&max,&index,n);
//printf("%5d\n%5d",max,index);
printf("%5lf\n%5d\n", max, index);
}
void fun(double b[],double *max,int *index,int m)
{
int i;
*max = b[0];
*index = 0;
for(i=1;i<m;i++)
if(*max<=b[i])
{
*index=i;
*max=b[i];
}

}

供参考~

index和max都没有初始化~
weixin_40290083 2019-09-08
  • 打赏
  • 举报
回复
1,数组长度定义为10,输入时N的值没有合法性判断。 2,MAX没有初始化,在FUN方法中也没有初始化,通常应初始化为下标为0的元素的值。
qq_45622459 2019-09-08
  • 打赏
  • 举报
回复
引用 5 楼 wowpH的回复:
引用 4 楼 qq_45622459 的回复:
难道还能返回两个参数
a[index],其中index是返回的最大值的下标。我问你a[index]是不是最大值。
就是运行结果错误,,
wowpH 2019-09-08
  • 打赏
  • 举报
回复
引用 4 楼 qq_45622459 的回复:
难道还能返回两个参数
a[index],其中index是返回的最大值的下标。我问你a[index]是不是最大值。
qq_45622459 2019-09-08
  • 打赏
  • 举报
回复
引用 2 楼 wowpH的回复:
说个和错误没关系的点,你可以直接返回下标,没必要带个参数传来传去。
难道还能返回两个参数
qq_45622459 2019-09-08
  • 打赏
  • 举报
回复
难道还能返回两个参数
wowpH 2019-09-08
  • 打赏
  • 举报
回复
说个和错误没关系的点,你可以直接返回下标,没必要带个参数传来传去。
qq_45622459 2019-09-08
  • 打赏
  • 举报
回复
是找数组最大值及下标

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧