定义两个3×4的矩阵,用数组名作为函数实参,分别求两个矩阵中的最大值。
时间: 2024-05-05 18:19:32 浏览: 11
好的,我可以帮您解决这个问题。以下是解决方案:
```c++
#include<iostream>
using namespace std;
void max_matrix(int arr[][4], int rows) {
int max_num = arr[0][0];
for(int i=0; i<rows; i++) {
for(int j=0; j<4; j++) {
if(arr[i][j] > max_num) {
max_num = arr[i][j];
}
}
}
cout<<"The maximum number is: "<<max_num<<endl;
}
int main() {
int matrix1[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int matrix2[3][4] = {{12,11,10,9},{8,7,6,5},{4,3,2,1}};
cout<<"Matrix 1:"<<endl;
max_matrix(matrix1, 3);
cout<<"\nMatrix 2:"<<endl;
max_matrix(matrix2, 3);
return 0;
}
```
输出结果:
```
Matrix 1:
The maximum number is: 12
Matrix 2:
The maximum number is: 12
```
希望对您有帮助!
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)