
用C语言写一个算法求两个矩阵的乘法运算。
3个回答
展开全部
//有关对齐和数组大小数值问题,自己另外解决
/* Note:Your choice is C IDE */
#include "stdio.h"
//矩阵arra和矩阵arrc的 行数 必须相等,这里为ROW
//矩阵arrb和矩阵arrc的 列数 必须相等,这里为COL
//矩阵arra的列数和矩阵arrb的行数必须相等,这里为MID
//arrc[r][c]=arra[r][0]*arrb[0][c] + arra[r][1]*arrb[1][c]
#define ROW 2
#define COL 3
#define MID 2
void print_array(int arrc[][COL]);
void main()
{
int c,r,m;
int arra[ROW][MID]={
{1,1},
{2,0}};
int arrb[MID][COL]={
{0,2,3},
{1,1,2}};
int arrc[ROW][COL]={0};
for(r=0;r<ROW;r++)
{
for(c=0;c<COL;c++)
{
for(m=0;m<MID;m++)
{
arrc[r][c]+=arra[r][m] * arrb[m][c];
}
}
}
print_array(arrc);
}
void print_array(int arrc[][COL])
{
int r,c;
for(r=0;r<ROW;r++)
{
for(c=0;c<COL;c++)
{
printf("%d ",arrc[r][c]);
}
printf("\n");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
请搜索百度百科“矩阵相乘”
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
include<fstream>
#include<iomanip>
#include<iostream>
#include<string>
using namespace std;
int main()
{
int row1,row2,col1,col2;
cout<<"Please input the row and col of the first matrix: "<<endl;
cin>>row1>>col1;
cout<<endl;
cout<<"Please input the row and col of the second matrix: "<<endl;
cin>>row2>>col2;
cout<<endl;
float a[100][100],b[100][100],c[100][100];
fstream outfile;
if(col1==row2)
{
outfile.open("1.txt");
}
for(int i=0;i<row1;i++)
{
for(int j=0;j<col1;j++)
{
outfile>>a[i][j];
}
}
outfile.close();
#include<iomanip>
#include<iostream>
#include<string>
using namespace std;
int main()
{
int row1,row2,col1,col2;
cout<<"Please input the row and col of the first matrix: "<<endl;
cin>>row1>>col1;
cout<<endl;
cout<<"Please input the row and col of the second matrix: "<<endl;
cin>>row2>>col2;
cout<<endl;
float a[100][100],b[100][100],c[100][100];
fstream outfile;
if(col1==row2)
{
outfile.open("1.txt");
}
for(int i=0;i<row1;i++)
{
for(int j=0;j<col1;j++)
{
outfile>>a[i][j];
}
}
outfile.close();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询