当前位置:首页 » 编程软件 » a2编程

a2编程

发布时间: 2023-05-23 10:17:35

① 计算机算法题!编程实现5个矩阵A1A2A3A4A5联乘积

你题目里面的矩阵有六个 啊 ,而且 5*10,30*20,20*25 不对吧!
我的代码在下面,你自己改几个数字吧。 下面标记了
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct matrix{
int row,col,num[40][40];
} a[5];
struct matrix pro(struct matrix a,struct matrix b)
{
struct matrix c;
int i,j,k;
c.row = a.row; c.col = b.col;
memset(c.num,sizeof(c.num),0);
for(i=0;i<c.row;i++)
{
for(j=0;j<c.col;j++)
{
for(k=0;k<a.col;k++)
c.num[i][j] += a.num[i][k] * b.num[k][j];
}
}
return c;
}
void out(struct matrix a)
{
int i,j;
for(i=0;i<a.row;i++)
{
for(j=0;j<a.col;j++)
printf("%5d ",a.num[i][j]);
puts("");
}
}
int main()
{
int i,j,k;
struct matrix ans;
a[0].row = 2; a[0].col = 3; /*设置行和列*/
a[1].row = 3; a[1].col =2;
a[2].row = 15; a[2].col = 5;
a[3].row = 5; a[3].col = 10;
a[4].row = 10; a[4].col = 25; /*这里进行更改就行*/
for(i=0;i<5;i++)
{
printf("please enter matrix %d ( %d * %d ):\n",i+1,a[i].row,a[i].col);
for(j=0;j<a[i].row;j++)
{
for(k=0;k<a[i].col;k++)
scanf("%d",&(a[i].num[j][k]));
}
}
for(i=0;i<4;i++)
{
ans = pro(a[i],a[i+1]);
}
puts("answer matrix is :");
out(ans);
system("pause");
}

热点内容
solidworkspcb服务器地址 发布:2025-07-18 22:50:35 浏览:815
怎么在堆叠交换机里配置vlan 发布:2025-07-18 22:42:35 浏览:623
java调用别人的接口 发布:2025-07-18 22:37:35 浏览:433
服务器四个节点如何联网 发布:2025-07-18 22:36:02 浏览:271
华强北什么地方休安卓手机 发布:2025-07-18 22:24:56 浏览:735
数据库的根本目标 发布:2025-07-18 21:37:50 浏览:938
压缩机的流速 发布:2025-07-18 21:37:40 浏览:407
三星怎么取消手机密码 发布:2025-07-18 21:33:50 浏览:630
安卓手机耳机如何弹窗显示电量 发布:2025-07-18 21:20:53 浏览:60
云服务器搭建需要什么工具 发布:2025-07-18 20:51:08 浏览:322