矩阵乘法能运行,但没有结果~
帮忙看看这个代码能运行但没有结果~代码如下~
程序代码:
#include<iostream> #define MAX_SIZE 10 using namespace std int main() { int i = 0, j = 0, s = 0, q = 0, NumOfColA, NumOfRowA, NumOfColB; int a[MAX_SIZE][MAX_SIZE], b[MAX_SIZE][MAX_SIZE], c[MAX_SIZE][MAX_SIZE]; cout << "输入的行列数均不能大于10!" << endl; cout << "请输入A矩阵相关信息:" << endl; cout << "行 NumOfRowA = "; cin >> NumOfRowA; cout << "列 NumOfColA = "; cin >> NumOfColA; //矩阵A的行对应矩阵B的列 cout << "请输入B矩阵相关信息:" << endl; cout << "列 NumOfColB = "; cin >> NumOfColB; cout << "请输入矩阵A元素" << endl; for (i = 0; i < NumOfRowA; i++) { for (j = 0; j < NumOfColA; j++) { cin >> a[i][j]; } } cout << "请输入矩阵B元素" << endl; for (j = 0; j < NumOfColA; j++) { for (s = 0; s < NumOfColB; s++) { cin >> b[j][s]; } } for (i = 0; i < NumOfRowA; i++) { for (s = 0; s < NumOfColB; s++) { for (j = 0; j < NumOfColA; j++) { q = q + a[i][j] * b[j][s]; } q = 0; c[i][s] = q; } } cout << "矩阵乘法的结果:" << endl; //输出矩阵结果 for (i = 0; i < NumOfRowA; i++) { for (j = 0; j < NumOfColB; j++) { cout << c[i][j] << "\t"; } cout << endl; } system("pause"); return 0; }
[此贴子已经被作者于2017-10-6 19:28编辑过]