Home > Back-end >  Define a number of functions (is a custom function), using a two-dimensional array as incoming param
Define a number of functions (is a custom function), using a two-dimensional array as incoming param

Time:09-18

: define a number of functions (is a custom function), using the two dimensional array as the incoming parameters, calculation of 2 d and the product of the two diagonal elements in an array, the main function of the input a two-dimensional array of 4 * 4, call the defined function, into the matrix, the output in the main function,
Recently learn C language, this is unlikely to function parameters, want to half a day or do not to come out, trouble, help me, thank you,

CodePudding user response:

For your reference
 
#include

Void Array1 (int arr [], [4], int * a, int * b)
{
int i, j;
for (i=0; i<4. I++)
{
for (j=0; J<4. J++)
{
If (I==j)
{
* a +=arr [I] [j];
* b *=arr [I] [j];
}
}
}
}

Void Array2 (int arr [], [4], int * a, int * b)
{
int i, j;
for (i=0; i<4. I++)
{
for (j=0; J<4. J++)
{
If (j==(3 I))
{
* a +=arr [I] [j];
* b *=arr [I] [j];
}
}
}
}

Int main ()
{
Int arr [4] [4]={0};
Int I, j, sum1=0, prod1=1, sum2=0, prod2=1;

for (i=0; i<4. I++)
{
for (j=0; J<4. J++)
The scanf (" % d ", & amp; Arr [I] [j]);
}

Array1 (arr, & amp; Sum1, & amp; Prod1);
Array2 (arr, & amp; Sum2, & amp; Prod2);

Printf (" sum1=% d, prod1=% d \ n ", sum1, prod1);
Printf (" sum2=% d, prod2=% d \ n ", sum2, prod2);

return 0;
}


  • Related