矩阵乘法+快速幂_C ++矩阵乘法程序

矩阵乘法+快速幂

Here you will get C++ matrix multiplication program.

在这里,您将获得C ++矩阵乘法程序。

What we are doing in this program.

我们在该程序中正在做什么。

Read number of rows and columns for two matrix.

读取两个矩阵的行数和列数。

Then check if matrix multiplication is possible or not.

然后检查是否可以进行矩阵乘法。

If not possible then show a message to user otherwise multiply them. Finally display the result.

如果不可能,则向用户显示一条消息,否则将其乘以。 最后显示结果。

C ++矩阵乘法程序 (C++ Matrix Multiplication Program)

#include<iostream>
 
using namespace std;
 
int main()
{
	int a[5][5],b[5][5],c[5][5],m,n,p,q,i,j,k;
	cout<<"Enter rows and columns of first matrix:";
	cin>>m>>n;
	cout<<"Enter rows and columns of second matrix:";
	cin>>p>>q;
 
	if(n==p)
	{
		cout<<"\nEnter first matrix:\n";
		for(i=0;i<m;++i)
			for(j=0;j<n;++j)
				cin>>a[i][j];
 
		cout<<"\nEnter second matrix:\n";
		for(i=0;i<p;++i)
			for(j=0;j<q;++j)
				cin>>b[i][j];
 
		cout<<"\nThe new matrix is:\n";
		for(i=0;i<m;++i)
		{
			for(j=0;j<q;++j)
			{
				c[i][j]=0;
				for(k=0;k<n;++k)
					c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
				cout<<c[i][j]<<" ";
		}
			cout<<"\n";
		}
	}
	else
		cout<<"\nSorry!!!! Matrix multiplication can't be done";
 
	return 0;
}

Output

输出量

C++ Matrix Multiplication Program

翻译自: https://www.thecrazyprogrammer.com/2012/09/c-program-to-multiply-two-matrices.html

矩阵乘法+快速幂

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值