计算两个同维数矩阵
小弟整天在离散数学中计算矩阵的乘法,经常算错.,算烦了,就写个程序来计算,准确率果然上来了.
先把程序弄下来,请大家不吝赐教.谢谢!
//This programe can caculatro the two matrixs' product
//Author Guo Xiaobing
//Time: 2007 / 12 / 5
#include <iostream.h>
//This function is used to caculator the two matrixs' product
void booleanreason(int[][10],int[][10],int[][10],int);
//This function is used to make user input matrix
void input_matrix(int[][10],int);
//this function is used to display the matrix user input
void output_matrix(int[][10],int);
int main()
{
int a[10][10],b[10][10],c[10][10]={0};
cout << "please input matrix's C "<<"\n";
int n;
cin >> n;
cout << "Please input the first matrix"<<"\n";
input_matrix(a,n);
cout << "The matrix you put is :"<<"\n";
output_matrix(a,n);
cout<<"Please input another matrix"<<"\n";
input_matrix(b,n);
cout<<"The another matrix you put is :"<<"\n";
output_matrix(b,n);
booleanreason(a,b,c,n);
cout<<"The booleanreason is :"<<"\n";
output_matrix(c,n);
return 0;
}
void booleanreason(int a[][10],int b[][10],int c[][10],int n)
{
int i,j,k;
for (i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
for(k=0;k<n;k++)
{
c[i][j]+=(a[i][k]*b[k][j]);
}
}
}
}
void input_matrix(int a[][10],int n)
{
for (int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
}
void output_matrix(int a[][10],int n)
{
for (int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout << a[i][j]<<" ";
}
cout << "\n";
}
}