68 lines
1.2 KiB
C
68 lines
1.2 KiB
C
|
#include<stdio.h>
|
|||
|
#include<stdlib.h>
|
|||
|
//<2F>Ǫ<EFBFBD><C7AA>Чڥ<D0A7><DAA5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>мg<D0BC><67>
|
|||
|
void mul(int **a ,int **b,int **c ,int m , int k ,int n){
|
|||
|
int i , j , l ,sum;
|
|||
|
|
|||
|
for (i=0;i<m;i++){
|
|||
|
for(j=0;j<n;j++){
|
|||
|
sum = 0;
|
|||
|
for(l=0;l<k;l++){
|
|||
|
sum += a[i][l]*b[l][j];
|
|||
|
}c[i][j]=sum;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
int main(){
|
|||
|
int i , j ,m=2,k=3,n=4;
|
|||
|
//<2F><><EFBFBD>w<EFBFBD>q<EFBFBD><71><EFBFBD>ӯx<D3AF>}
|
|||
|
int a[2][3]={{1,2,7},{3,4,1}};
|
|||
|
int b[3][4]={{5,6,2,4},{7,8,2,4},{7,2,6,1}};
|
|||
|
//<2F>ھ<EFBFBD>m,k,n<>t<EFBFBD>m<EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD>
|
|||
|
int **arr_a = (int**)malloc(m * sizeof(int*));
|
|||
|
int **arr_b = (int**)malloc(k * sizeof(int*));
|
|||
|
int **arr_c = (int**)malloc(m * sizeof(int*));
|
|||
|
for(i=0;i<m;i++){
|
|||
|
arr_a[i] = (int*)malloc(k*sizeof(int));
|
|||
|
arr_c[i] = (int*)malloc(n*sizeof(int));
|
|||
|
}
|
|||
|
for(i=0;i<k;i++){
|
|||
|
arr_b[i] = (int*)malloc(n*sizeof(int));
|
|||
|
}
|
|||
|
//<2F><><EFBFBD><EFBFBD>Ū<EFBFBD>i arr_a<5F>Marr_b
|
|||
|
for (i=0;i<m;i++){
|
|||
|
for(j=0;j<k;j++){
|
|||
|
arr_a[i][j]=a[i][j];
|
|||
|
}
|
|||
|
}
|
|||
|
for (i=0;i<k;i++){
|
|||
|
for(j=0;j<n;j++){
|
|||
|
arr_b[i][j]=b[i][j];
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
mul(arr_a,arr_b,arr_c,m,k,n);
|
|||
|
|
|||
|
for (i=0;i<m;i++){
|
|||
|
for(j=0;j<n;j++){
|
|||
|
printf("c[%d][%d]=%d\n",i,j,arr_c[i][j]);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//<2F>ھگx<DAAF>}<7D>j<EFBFBD>p<EFBFBD><70><EFBFBD><EFBFBD><EFBFBD>O<EFBFBD><4F><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD>
|
|||
|
free (arr_a);
|
|||
|
free (arr_b);
|
|||
|
free (arr_c);
|
|||
|
for(i=0;i<m;i++){
|
|||
|
free (arr_a[i]);
|
|||
|
free (arr_c[i]);
|
|||
|
}
|
|||
|
for(i=0;i<k;i++){
|
|||
|
free (arr_b[i]);
|
|||
|
}
|
|||
|
|
|||
|
return 0 ;
|
|||
|
}
|