计算两个同维数矩阵

geniuaihuo 2007-12-04 10:15:56
小弟整天在离散数学中计算矩阵的乘法,经常算错.,算烦了,就写个程序来计算,准确率果然上来了.

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

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

}














...全文
215 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ollydbg23 2008-01-03
  • 打赏
  • 举报
回复
?你发这个帖子是什么意思?让大家欣赏?还是有问题?啥意思?

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧