计算两个同维数矩阵

geniuaihuo geniuaihuo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
小弟整天在离散数学中计算矩阵的乘法,经常算错.,算烦了,就写个程序来计算,准确率果然上来了.

先把程序弄下来,请大家不吝赐教.谢谢!

//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";
}

}














...全文
评论 1
收藏 已收藏
分享
返回顶部
geniuaihuo
C++ 语言 65,214 成员 250,514 内容