- //一个5*3矩阵,编程实现求出矩阵中的最大值并指出其所在的行号和列号
- #include <stdio.h>
- int i,j,temp,mRow,mCol;
- void max(int arr[5][3]){
-
- int max = arr[0][0];
- for(i=0;i<5;i++){
- for(j=0;j<3;j++){
- if(max < arr[i][j]){
- temp = max;
- max = arr[i][j];
- arr[i][j] = temp;
- mRow = i;
- mCol = j;
- }
- }
- }
- printf("最大值为%d,其行号为%d,其列号为%d\n",max,mRow,mCol);
- }
-
- int main(){
- int a[5][3] = {53,28,39,45,69,88,92,56,12,35,49,69,68,58,47};
- for(i=0;i<5;i++){
- for(j=0;j<3;j++){
- printf("a[%d][%d] = %d\t",i,j,a[i][j]);
- }
- printf("\n");
- }
- max(a);
- return 0;
- }
复制代码
|
|