c++二维数组最大值最小值
时间: 2023-11-02 18:06:42 浏览: 124
二维数组最大值最小值
以下是Python代码示例,演示如何在二维数组中找到最大值和最小值:
```python
arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
# 找到最大值
max_val = arr[0][0]
for row in arr:
for val in row:
if val > max_val:
max_val = val
print("最大值:", max_val)
# 找到最小值
min_val = arr[0][0]
for row in arr:
for val in row:
if val < min_val:
min_val = val
print("最小值:", min_val)
```
输出:
```
最大值: 9
最小值: 1
```
阅读全文