當前位置:首頁 » 編程軟體 » 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");
}

熱點內容
安卓泰拉瑞亞去哪裡買 發布:2025-07-18 20:01:05 瀏覽:694
flash編譯器 發布:2025-07-18 19:49:38 瀏覽:487
memcached源碼分析 發布:2025-07-18 19:22:42 瀏覽:866
android展示圖片 發布:2025-07-18 19:21:24 瀏覽:594
一台伺服器5個IP怎麼分配 發布:2025-07-18 19:12:34 瀏覽:862
貴陽分布式存儲行情 發布:2025-07-18 19:12:31 瀏覽:361
車場伺服器和工控機是如何連接的 發布:2025-07-18 19:10:19 瀏覽:938
計算機編程學什麼好 發布:2025-07-18 19:06:49 瀏覽:410
網吧用的伺服器是什麼伺服器 發布:2025-07-18 18:40:15 瀏覽:938
ftp命令使用 發布:2025-07-18 18:13:05 瀏覽:47