1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <stdio.h> //返回最小值,下标用址传递的方式传回给主函数 int fun(int data[][6],int *mini,int *minj){ int minNum = data[0][0]; for(int i=0;i<5;i++){ for(int j=0;j<6;j++){ if(data[i][j]<minNum){ minNum = data[i][j]; *mini = i; *minj = j; } } } return minNum; } int main(){ int data[5][6] = {-93, 45, 0, -28, -60, 81, 63, 17, 9, -75, 32, -14, -37, 8, -48, 54, 92, -18, 70, -2, 39, -84, 59, -43, -96, 3, 23, -67, -51, 26}; int minNum,mini,minj; minNum = fun(data,&mini,&minj); printf("最小值%d所在行下标是%d,列下标是%d,即第%d行第%d列",minNum,mini,minj,mini+1,minj+1); return 0; }
|