Cộng, trừ và nhân hai ma trận


Mã:
#include "conio.h"
#include "iostream.h"
#define max 100
/*Nhap ma tran he so*/
void NhapMaTran(float A[max][max], int m, int n){
	for(int i = 0; i<m; i++)
	for(int j = 0; j<n; j++) {
		cout<<"a["<<i<<"]["<<j<<"] = ";
		cin>>A[i][j];
	}
}

/*Xuat ma tran*/
void XuatMaTran(float A[max][max], int m, int n) {
	for(int i=0 ; i<m; i++){
		cout<<endl;
		for(int j=0 ; j<n; j++)
			cout<<A[i][j]<<"\t";
	}
}
/*C = A+B*/
void CongMaTran(float A[max][max], float B[max][max], float C[max][max], int m, int n) {
	for(int i = 0; i<m; i++)
	for(int j = 0; j<n; j++)
		C[i][j] = A[i][j]+B[i][j];

}
/*A cap mxn * B cap nxp = C cap mXp*/
void NhanMaTran(float A[max][max], float B[max][max], float C[max][max], int m, int n, int p){
	for(int i = 0; i<m; i++)
		for(int k = 0; k<p; k++) {
			C[i][k]=0;
			for(int j = 0; j<n; j++)
				C[i][k] = C[i][k]+A[i][j]*B[j][k];
		}
}
/*Chuong trinh chinh*/
void main(){
	int m=3,n=2,p=3;
	float A[max][max],B[max][max],C[max][max],D[max][max];
	clrscr();
	cout<<"Nhap ma tran A cap "<<m<<"x"<<n<<endl;
	NhapMaTran(A,m,n);
	cout<<"Nhap ma tran B cap "<<m<<"x"<<n<<endl;
	NhapMaTran(B,m,n);
	cout<<"Nhap ma tran C cap "<<n<<"x"<<p<<endl;
	NhapMaTran(C,n,p);
	cout<<"Ma tran A\n";
	XuatMaTran(A,m,n);
	cout<<"\nMa tran B\n";
	XuatMaTran(B,m,n);
	cout<<"\nMa tran C\n";
	XuatMaTran(C,n,p);
	cout<<"\nMa tran D = A+B\n";
	CongMaTran(A,B,D,m,n);
	XuatMaTran(D,m,n);
	cout<<"\nMa tran D = A.C\n";
	NhanMaTran(A,C,D,m,n,p);
	XuatMaTran(D,n,p);
	getch();
}