// 方法1: intmain() { int arr[MAX_ROW][MAX_COL]; int n, m; // n行 m列 int i, j, k; // 输入数组的行数和列数 printf("Enter the number of rows (1-10): "); scanf("%d", &m); printf("Enter the number of columns (1-10): "); scanf("%d", &n); printf("Enter the elements of the array:\n"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { scanf("%d", &arr[i][j]); } } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { int isSaddlePoint = 1; // 检查是否为行最大值 for (k = 0; k < n; k++) { if (arr[i][j] < arr[i][k]) { isSaddlePoint = 0; break; } } // 检查是否为行最小值 for (k = 0; k < m; k++) { if (arr[i][j] > arr[k][j]) { isSaddlePoint = 0; break; } } if (isSaddlePoint) { printf("Saddle point found at (%d, %d): %d\n", i + 1, j + 1, arr[i][j]); } } }
return0; }
// 方法2: intmain() { int arr[MAX_ROW][MAX_COL]; int n, m; // n行 m列 int i, j, k; // 输入数组的行数和列数 printf("Enter the number of rows (1-10): "); scanf("%d", &m); printf("Enter the number of columns (1-10): "); scanf("%d", &n); printf("Enter the elements of the array:\n"); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { scanf("%d", &arr[i][j]); } } for (i = 0; i < m; i++) { int max = 0; for (j = 1; j < n; j++) { if (arr[i][max] < arr[i][j]) { max = j; } } int min = 0; for (j = 1; j < m; j++) { if (arr[min][max] > arr[j][max]) { min = j; } } if (arr[i][max] == arr[min][max]) { printf("Saddle point found at (%d, %d): %d\n", i + 1, max + 1, arr[i][max]); } }