c语言写出)在啊n列(n<-10)的二維整数数组中,按照以、下要求选出一个数。首先从每行中选出最大数,再从选出的口个最大数中选出最小数。 程序运行示例: Please enter the order of the matrix:3 Please input the elements of the matrix: 9 2 3 4 5 8 7 2 1 The minimum of maximum number is 7. 輸入提示:“Please enter the order of the matrix: 输入格式:%d 輸入提示:"Please input the elements of the matrix.n 輸入格式:%d 輸出提示:“The minimum of maximum number is %d. 1n"
时间: 2024-03-03 11:47:15 浏览: 64
以下是题目要求的 C 语言代码:
```c
#include <stdio.h>
#define MAX_N 10
int main() {
int n, matrix[MAX_N][MAX_N];
printf("Please enter the order of the matrix: ");
scanf("%d", &n);
printf("Please input the elements of the matrix:\n");
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &matrix[i][j]);
}
}
int max_row[n], min_max;
// 找每一行的最大值
for (int i = 0; i < n; i++) {
int max = matrix[i][0];
for (int j = 1; j < n; j++) {
if (matrix[i][j] > max) {
max = matrix[i][j];
}
}
max_row[i] = max;
}
// 找所有最大值中的最小值
min_max = max_row[0];
for (int i = 1; i < n; i++) {
if (max_row[i] < min_max) {
min_max = max_row[i];
}
}
printf("The minimum of maximum number is %d.\n", min_max);
return 0;
}
```
该程序首先读入一个 n\*n 的矩阵,然后遍历每一行找到最大值,将这些最大值存入一个数组中。最后遍历这个数组找到最小值,即为答案。
阅读全文