Data: mat1.txt
/*
s—ρ‚ΜA+B(˜a)AA*C(Ο)AA^t“]’us—ρ
‚π‹‚ί‚ιB

A= 1 3  B= 2  -2   C=1  0 -1
  -1 2     0   1     2  1   2
   2 1     1   3
*/
#include 
#include 
#define M 3
#define N 3

void inputdata(FILE *fdata,double x[][N],int m,int n);
void matsum(double x[][N],double y[][N],double z[][N],int m,int n);
void matprod(double x[][M],double y[][N],double z[][N],int m, int k, int n);
void mattrans(double x[][M],double y[][N],int m,int n);
void out_res(double a[][N],int m,int n);

main()
{
 double a[3][N],b[3][N],c[2][N],sum1[3][N],prod1[3][N],trans1[3][N];
 FILE *fdata;
 fdata=fopen("mat1.txt","r");
 inputdata(fdata,a,3,2);
 inputdata(fdata,b,3,2);
 inputdata(fdata,c,2,3);

 matsum(a,b,sum1,3,2);
 matprod(a,c,prod1,3,2,3);
 mattrans(a,trans1,3,2);
 printf("A+B \n");
 out_res(sum1,3,2);
 printf("A*B \n");
 out_res(prod1,3,3);
 printf("A' \n");
 out_res(trans1,2,3);
 fclose(fdata);
}

void inputdata(FILE *fdata,double x[][N],int m,int n)
{
 int i,j;
 double d;
 for(i=0;i<=m-1;i++)
   for(j=0;j<=n-1;j++){
     fscanf(fdata,"%lf",&d);
     x[i][j]=d;
     }
}

void matsum(double x[][N],double y[][N],double z[][N],int m, int n)
{
 int i,j;
 for (i=0;i<=m-1;i++)
   for (j=0;j<=n-1;j++)
     z[i][j]=x[i][j]+y[i][j];
}

void matprod(double x[][M],double y[][N],double z[][N], int m, int k, int n)
{
 int i,j,r;
 double a;
 for(i=0;i<=m-1;i++)
   for(j=0;j<=n-1;j++){
     a=0;
     for(r=0;r<=k-1;r++)a=a+x[i][r]*y[r][j];
     z[i][j]=a;
     }
}

void mattrans(double x[][M],double y[][N],int m,int n)
{
 int i,j;
 for(i=0;i<=m-1;i++)
   for(j=0;j<=n-1;j++)
     y[j][i]=x[i][j];
}

void out_res(double x[][N],int m,int n)
{
 int i,j;
 for(i=0;i<=m-1;i++){
   for(j=0;j<=n-1;j++)printf("%10.3f",x[i][j]);
   printf("\n");
   }
}


[o—ΝŒ‹‰Κ]

A+B 
     3.000     1.000
    -1.000     3.000
     3.000     4.000
A*B 
     7.000     3.000     5.000
     3.000     2.000     5.000
     4.000     1.000     0.000
A' 
     1.000    -1.000     2.000
     3.000     2.000     1.000


Back to C Language

Google




BLOG
PICASAWEB
Panoramio


REF:


C‚Ι‚ζ‚铝Œvƒf[ƒ^‰πΝ“ό–ε