任意阶矩阵的乘法
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
C-source:
<span style="color:#333333;">#include<stdio.h>
#include<malloc.h>
int main(void)
{
int m,g,n;
int i,j,k; int number;
double **a=NULL,**b=NULL,**result=NULL;
printf("Please input number:\n");
scanf("%d",&number); while(number!=)
{
number--; printf("Please input m,g,n:\n");
scanf("%d%d%d",&m,&g,&n); a=(double**)malloc(m*sizeof(double*));
for(i=;i<m;i++)
a[i]=(double*)malloc(g*sizeof(double)); printf("Please input the first jz:\n");
for(i=;i<m;i++)
for(j=;j<g;j++)
scanf("%lf",&a[i][j]); b=(double**)malloc(g*sizeof(double *));
for(i=;i<g;i++)
b[i]=(double*)malloc(n*sizeof(double)); printf("Please input the second jz\n");
for(i=;i<g;i++)
for(j=;j<n;j++)
scanf("%lf",&b[i][j]); result=(double**)malloc(m*sizeof(double*));
for(i=;i<m;i++)
result[i]=(double*)malloc(n*sizeof(double)); for(i=;i<m;i++)
for(j=;j<n;j++)
result[i][j]=; for(i=;i<m;i++)
for(j=;j<n;j++)
for(k=;k<g;k++)
result[i][j]+=a[i][k]*b[k][j]; printf("answer:\n");
for(i=;i<m;i++)
{
for(j=;j<n;j++)
printf("%5g",result[i][j]);
printf("\n");
}
}
for(i=;i<m;i++)
{
free(a[i]);
a[i]=NULL;
free(result[i]);
result[i]=NULL;
}
free(a);
a=NULL;
free(result);
result=NULL; for(i=;i<g;i++)
{ free(b[i]);
b[i]=NULL;
}
free(b);
b=NULL; return ;
}