数组的乘积

 1 #include "stdafx.h"
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 #include <string.h>
 5 
 6 void MATRIX_MULTIPLY(int (*a)[3],int (*b)[4])
 7 {
 8     int i = 0,j = 0,k=0;
 9     int *c[2] = {0};
10     c[0] = (int*)malloc(sizeof(int)*4);
11     c[1] = (int*)malloc(sizeof(int)*4);
12     memset(c[0],0,sizeof(int)*4);
13     memset(c[1],0,sizeof(int)*4);
14 
15     for(i=0;i<2;i++)
16     {
17         for(j=0;j<4;j++)
18         {
19             for(k=0;k<3;k++)
20                 c[i][j] += a[i][k]*b[k][j];
21         
22         }
23     }
24     for(i=0;i<2;i++)
25     {
26         for(j=0;j<4;j++)
27             printf("%d ",c[i][j]);
28         printf("\n");
29     }
30 }
31 
32 int _tmain(int argc, _TCHAR* argv[])
33 {
34     int a[2][3] = {{1,2,3},{4,5,6}};
35     int b[3][4] = {{1,0,8,4},{7,6,4,5},{4,3,2,1}};
36     MATRIX_MULTIPLY(a,b);
37     return 0;
38 }
View Code

 

posted @ 2013-12-26 14:13  挡不住会飞的鸡  阅读(130)  评论(0编辑  收藏  举报