清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#include<iostream> #include<cstdlib> #include<cstring> #include<iomanip> using namespace std; void multmat(int A[], int B[], int C[], int m, int n, int p) { int i, j, k; for(i = 0; i < m; ++i) for(j = 0; j < p; ++j) { int s = 0; for(k = 0; k < n; ++k) s += A[i*n + k]*B[k*p + j]; C[i*p + j] = s; } return; } int main(void) { const int MAX = 1000; int A[MAX], B[MAX], C[MAX]; int m, n, p; cout << "input m,n,p: "; cin >> m >> n >> p; if(m*n >= MAX || n*p >= MAX || m*p >= MAX) { cout << "mem ex." << endl; return -1; } cout << "input matrix A: " << endl; for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) cin >> A[i*n + j]; cout << "input matrix B: " << endl; for(int i = 0; i < n; ++i) for(int j = 0; j < p; ++j) cin >> B[i*p + j]; multmat(A, B, C, m, n, p); cout<< "the matrix C is: "<< endl; for(int i = 0; i < m; ++i) { for(int j = 0; j < p; ++j) { cout << setw(3) << C[i*p + j] << ' '; } cout << endl; } system("pause"); return 0; }