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;
}