找出3x3矩阵里行最大同时列最小的数所在的行和列
作者:互联网
需要注意二维数组的传参。
1.
/*计算二维数组鞍点的下标*/
void FindSaddlePoint(int **arr, int ROW, int COL, int *row, int *col)
{
int i = 0;
int j = 0;
int ROWMAX = 0;
if(arr == NULL)return;/*检查数组*/
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
{
printf("%d ", arr[i][j]);/*打印二维数组*/
}
printf("\n");
}
for(i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
{
if(arr[i][j] >= ROWMAX)/*找出该行的最大数ROWMAX*/
{
ROWMAX = arr[i][j];
*row = i;
*col = j; /*保存行列*/
}
}
printf("ROWMAX:%d\n", ROWMAX);
for(j=0; j<ROW; j++)/*检查ROWMAX是否是该列的最小值*/
{
if(arr[j][*col] < ROWMAX) break;/*存在比ROWMAX还小的就跳出循环*/
if(j == ROW-1) printf("%d, %d\n", *row, *col);/*确定ROWMAX为该列最小值*/
}
}
}
void test06(void)
{
int a[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int *b[3];
int i = 0;
int j = 0;
int row = 0;
int col = 0;
int ROW = sizeof(a)/sizeof(a[0]);
int COL = sizeof(a[0])/sizeof(a[0][0]);
printf("ROW:%d, COL:%d\n", ROW, COL);
b[0] = a[0];
b[1] = a[1];
b[2] = a[2];
// scanf("%d %d %d\n"\
// "%d %d %d\n"\
// "%d %d %d"
// ,&a[0][0], &a[0][1], &a[0][2]
// ,&a[1][0], &a[1][1], &a[1][2]
// ,&a[2][0], &a[2][1], &a[2][2]
// );
FindSaddlePoint(b, 3, 3, &row, &col);
}
//如此定义函数
void FindSaddlePoint(int (*arr)[3], int ROW, int COL, int *row, int *col)
//传递参数
FindSaddlePoint(a, 3, 3, &row, &col);
标签:ROWMAX,arr,int,里行,行和列,FindSaddlePoint,3x3,col,row 来源: https://blog.csdn.net/SanShuiGeGe/article/details/98498076