求教一下这个问题用c语言怎么实现的
矩阵P(2行3列)乘以 矩阵R(3行3列) 所得结果再 乘以 矩阵R,感谢解答!
#include <stdio.h> int main(void) { int p[2][3]= {{1,2,3},{4,5,6}}, r[3][3]= {{1,2,3},{4,5,6},{7,8,9}}, c[2][3]; int count,n,m,i; for(i = 0; i < 2; i++) { for(m = 0; m < 3; m++) { for(n = 0,count = 0; n < 3; n++) count += p[i][n]*r[n][m]; c[i][m] = count; } } for(i = 0; i < 2; i++) { for(m = 0; m < 3; m++) { for(n = 0,count = 0; n < 3; n++) count += c[i][n]*r[n][m]; p[i][m] = count; } } for(n = 0; n < 2; n++) { for(m = 0; m < 3; m++) printf("%d ",p[n][m]); printf("\n"); } return 0; }
[此贴子已经被作者于2017-1-31 19:49编辑过]
#include <stdio.h> int main(void) { int p[2][3]= {{1,2,3},{4,5,6}}, r[3][3]= {{1,2,3},{4,5,6},{7,8,9}}, c[2][3]; int count,n,m,i; int N = 5; while(N--) { for(i = 0; i < 2; i++) { for(m = 0; m < 3; m++) { for(n = 0,count = 0; n < 3; n++) count += p[i][n]*r[n][m]; c[i][m] = count; } } for(i = 0; i < 2; i++) { for(m = 0; m < 3; m++) { for(n = 0,count = 0; n < 3; n++) count += c[i][n]*r[n][m]; p[i][m] = count; } } for(n = 0; n < 2; n++) { for(m = 0; m < 3; m++) printf("%d ",p[n][m]); printf("\n"); } return 0; }
[此贴子已经被作者于2017-2-1 23:56编辑过]