Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How does C language transfer matrix to function? I hope there are concrete examples;
How does C language transfer matrix to function? I hope there are concrete examples;
Floating-point matrix (float * a [3])

return(a[0][0]+a[0][2]+a[ 1][ 1]+a[2][0]+a[2][2]);

}

int i,j;

Floating point a[3][3], * p [3];

for(I = 0; I<3; i++)for(j = 0; j & lt3; j++){

scanf("%f ",& ampa[I][j]); //floating-point format %f

}

p[0]= & amp; a[0][0]; p[ 1]= & amp; a[ 1][0]; p[2]= & amp; a[2][0]; // 3 pointers

printf("sum=%0.2f\n ",matrix(p)); //Call.

============

General examples (known array rows and columns, dynamically allocated arrays) how to pass numerical values:

# include & ltstdio.h & gt

void fun 1(int *mat,int N_row,int N_col){

int i,j;

for(j = 0; j & ltN _ rowj++){

for(I = 0; I<N _ coli++) printf("%d ",mat [j * n _ col+I]);

printf(" \ n ");

}

}

void fun2(int **mat,int N_row,int N_col){

int i,j;

for(j = 0; j & ltN _ rowj++){

for(I = 0; I<N _ coli++) printf("%d ",mat [j] [i]);

printf(" \ n ");

}

}

int main()

{

int arr[3][4]={{ 1 1, 12, 13, 14},{2 1,22,23,24},{3 1,32,33,34 } };

int * * a;

int NR,NC,j,I;

fun 1。 arr[0][0],3,4);

printf(" input nrow ncol \ n ");

scanf("%d %d ",& ampNR,& ampNC);

a =(int * *)malloc(sizeof(int *)* NR);

for(j = 0; j & ltNR; j++){

a[j]=(int *)malloc(sizeof(int)* NC);

}

Printf ("input matrix data \ n");

for(j = 0; j & ltNR; j++)for(I = 0; I & ltNC;; i++) scanf("%d ",& ampa[j][I]);

fun2( a,NR,NC);

Returns 0;

}