求前辈帮助
已知A是一个3*4的矩阵,B是一个4*5的矩阵,编程求A*B得到的新矩阵C并输出C
#include <iostream> template<size_t M, size_t N, size_t P, typename T> void MatrixMultiplies( const T (&a)[M][N], const T (&b)[N][P], T (&c)[M][P] ) { for( size_t i=0; i!=M; ++i ) { for( size_t j=0; j!=P; ++j ) { c[i][j] = 0; for( size_t k=0; k!=N; ++k ) { c[i][j] += a[i][k] * b[k][j]; } } } } template<size_t R, size_t C, typename T> void MatrixOutput( const T (&m)[R][C] ) { for( size_t r=0; r!=R; ++r ) { for( size_t c=0; c!=C; ++c ) std::cout << '\t' << m[r][c]; std::cout << '\n'; } } int main() { int a[2][3] = { 1, 0, 2 , -1, 3, 1 }; int b[3][2] = { 3, 1 , 2, 1 , 1, 0 }; int c[2][2]; MatrixMultiplies( a, b, c ); MatrixOutput( a ); std::cout << "*\n"; MatrixOutput( b ); std::cout << "=\n"; MatrixOutput( c ); std::cout << std::endl; return 0; }