求助C++动态数组的相关问题!
要求编写C++函数,找寻并输出一个(自己建立的)m×n二维数组的最大/小值。
2017-03-13 21:32
程序代码:#include <cstddef>
template<typename T, size_t M, size_t N>
T maxofmtx( const T (&mtx)[M][N] )
{
T ret = mtx[0][0];
for( size_t r=0; r!=M; ++r )
for( size_t c=0; c!=N; ++c )
ret = ret<mtx[r][c] ? mtx[r][c] : ret;
return ret;
}
#include <iostream>
using namespace std;
int main( void )
{
int a[3][3] = { 1, 2, 3
, 6, 5, 4
, 7, 9, 8 };
cout << maxofmtx(a) << endl;
}
2017-03-14 09:47
2017-03-15 19:23