问题详情

以下函数 findmax 拟实现在数组中查找最大值并作为函数值返回 , 但程序中有错导致不能实现预定功能

#define MIN -2147483647

int findmax (int x[],int n)

{ int i,max;

for(i=0;i<n;i++)

{ max=MIN;

if(max<x[i]) max=x[i];}

return max;

}

造成错误的原因是

A) 定义语句 int i,max; 中 max 未赋初值

B) 赋值语句 max=MIN; 中,不应给 max 赋 MIN 值

C) 语句 if(max<x[i]) max=x[i]; 中判断条件设置错误

D) 赋值语句 max=MIN; 放错了位置

参考答案
您可能感兴趣的试题