Chương trình nhân 2 ma trận dùng bộ nhớ động nhưng bị lỗi. t sửa mãi mà ko đc. bạn nào giúp vs.
#include <iostream>
using namespace std;
void InputMatrix(int **A,int &r, int &c,char &symbol){
A= new int *[r];
if (A==NULL) cout <<"khong du bo nho de cap phat";
else {
for (int i=0;i<r;i++){
A[i]= new int [c];
if (A[i]==NULL){
cout <<"khong du bo nho"<<endl;
break;
}
else{
for (int j=0;j<c;j++){
cout << symbol<<"["<<i+1<<"]["<<j+1<<"]= ";
cin >> A[i][j];
}
}
}
}
void NhanMatrix(int **A,int **B, int **C,int &r1, int &c1,int &r2,int &c2){
if (c1!=r2) cout << "khong the nhan 2 ma tran"<<endl;
else{
for (int i=0; i<r1;i++){
for (int j=0; j<c2; j++){
C[i][j]=0;
for (int k=0; k<r2;k++){
C[i][j] += A[i][k] * B[k][j];
}
}
}
}
}
void DisplayMatrix(int **A,int &r, int &c){
for (int i=0;i<r; i++){
for (int j=0;j<c;j++){
cout << A[i][j] <<" ";
}
cout <<endl;
}
}
void FreeMatrix(int **A, int &r){
for (int i=0; i<r, i++){
delete [] A[i];
}
delete A;
}
int main (){
int r1,r2,c1,c2;
int **A, **B, **C;
cout << "nhap so hang cua ma tran A: "; cin >>r1;
cout << "nhap so cot cua ma tran A: "; cin >> c1;
cout << "nhap so hang cua ma tran B: "; cin >>r2;
cout << "nhap so cot cua ma tran B: "; cin >>c2;
InputMatrix(A,r1,c1,'A'); // nhap ma tran A
InputMatrix(B,r2,c2,'B'); // nhap ma tran B
cout << "ma tran A la"<<endl;
DisplayMatrix(A,r1,c1);
cout << "ma tran B la"<<endl;
DisplayMatrix(B,r2,c2);
NhanMatrix(A,B,C,r1,c1,r2,c2);
cout<< "tich 2 ma tran la: "<< endl;
DisplayMatrix (C,r1,c2);
FreeMatrix(A,r1);
FreeMatrix(B,r2);
system ("pause");
return 0;
}