跳到正文

个人记录

矩阵乘法

yyytttzzz约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年3月9日
收录
2026年11月28日
更新
2026年11月28日
篇幅
约 1 分钟

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
int n,k,m;
int a[105][105],b[105][105],c[105][105];
int main(){
	cin>>n>>k>>m;
	//输入a数组 
	for(int i=1;i<=n;i++)
		for (int j=1;j<=k;j++)
			cin>>a[i][j];
	//输入b数组 
	for(int i=1;i<=k;i++)
		for (int j=1;j<=m;j++)
			cin>>b[i][j];
	//求c数组 
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			for(int l=1;l<=k;l++)//枚举a第i行每个数 
				c[i][j]+=a[i][l]*b[l][j];
	//输出
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			cout<<c[i][j]<<" ";
		cout<<endl;}
	 
	return 0;
} 
原文