當前位置:首頁 » 編程軟體 » 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-09-17 08:45:44 瀏覽:435
白條密碼是什麼情況 發布:2025-09-17 08:43:01 瀏覽:315
高中信息演算法與程序 發布:2025-09-17 08:41:34 瀏覽:22
伺服器禁止設置幾個ip 發布:2025-09-17 08:41:26 瀏覽:500
側限壓縮儀 發布:2025-09-17 08:41:24 瀏覽:170
php登陸系統 發布:2025-09-17 08:35:55 瀏覽:416
wincc全局腳本中加減運算 發布:2025-09-17 08:05:48 瀏覽:334
如何將離線緩存轉至qq文件視頻 發布:2025-09-17 07:55:45 瀏覽:301
石油石化存儲 發布:2025-09-17 07:50:38 瀏覽:482
java冪 發布:2025-09-17 07:50:38 瀏覽:259