高仿模拟练习,补全 found 标记处空缺,答案点击按钮展开
fun函数求二维int数组中每一行的最大值,再把所有行最大值累加返回,请补全found空缺。
#include <stdio.h>
int fun(int arr[][3],int row)
{
int i,j,row_max,total=0;
for(i=0;i<row;i++)
{
/**********found**********/
row_max = ___1___;
for(j=1;j<3;j++)
{
/**********found**********/
if(arr[i][j]>row_max) row_max=___2___;
}
/**********found**********/
total = total + ___3___;
}
return total;
}
int main()
{
int a[2][3]={{1,3,2},{6,4,5}};
printf("total=%d\n",fun(a,2));
return 0;
}
arr[i][0]
arr[i][j]
row_max
第1空初始化行最大值row_max;第2空比较更新当前行最大值;第3空把每行最大值累加至total。测试二维数组{{1,3,2},{6,4,5}}输出total=9。