用C语言写一个算法求两个矩阵的乘法运算。

 我来答
百度网友5ea2af8
2013-10-15 · 超过12用户采纳过TA的回答
知道答主
回答量:29
采纳率:0%
帮助的人:30.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");
    }
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
奇闻轶史
2013-10-15 · TA获得超过134个赞
知道小有建树答主
回答量:400
采纳率:25%
帮助的人:119万
展开全部
请搜索百度百科“矩阵相乘”
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zhuimengtian
2013-10-15 · 超过11用户采纳过TA的回答
知道答主
回答量:82
采纳率:0%
帮助的人:30.6万
展开全部
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();
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式