Home > Back-end >  C output a maximum of 4 * 4 matrix diagonal and coordinate ~ my coordinate is always wrong
C output a maximum of 4 * 4 matrix diagonal and coordinate ~ my coordinate is always wrong

Time:09-23

# include "stdio.h"
Void ARR (int STR [4] [4])
{int Max=0, I=0, j=0;
Max=STR [0] [0]. To look for a maximum of two diagonals,//and output position

for(i=0; i<4. I++)
{
For (j=0; j<4. J++)
{
If ((I==j) | | (I + j==3))
{
Max=STR [I] [j] & gt; Max? STR [I] [j] : Max;
}
}
}
Printf (" the maximum diagonal=% d \ n ", Max).
Printf (" row=% d \ t, column=% d \ n ", I, j);

for(i=0; i<4. I++)//judgment, if there are multiple identical, maximum output respectively their coordinates
For (j=0; j<4. J++)
{if ((I==j) | | (I + j==3))
If (STR [I] [j]==Max)
{
Printf (" other lines of the same maximum: % d \ t, columns: % d \ n ", I + 1, j + 1);
}
}
}


Int main ()
{
Int STR [4], [4], I=0, j=0;
Int row=0; Int col=0;
Long the mul=1;
Float s=0.0;
Int Max=0;
Printf (" please enter your 4 * 4 array! \n");
for(i=0; i<4. I++)
{
For (j=0; j<4. J++)
{
The scanf (" % d ", & amp; STR [I] [j]);
} printf (" \ n ");
}//with double loop control, input matrix
for (i=0; i<4. I++)
{the for (j=0; j<4. J++)
Printf (" % d "10, STR [I] [j]);
Printf (" \ n ");
}//with double loop control, the output of the original matrix

//for each element on the two diagonals and
for(i=0; i<4. I++)
For (j=0; j<4. J++)
{
If ((I==j) | | (I + j==3))
S +=STR [I] [j].
}
Printf (" \ n the sum of the elements on two diagonal is % f \ n ", s);

//two diagonally upward, column subscript are the product of an even number of elements of
S=1.0;
for(i=0; i<4. I++)
For (j=0; j<4. J++)
{
If (((I==j) | | + j==3) (I) & amp; & (I % 2==0) & amp; & (j % 2==0))
S *=STR [I] [j];
}
Printf (" two diagonally upward, column subscripts are an even number of elements of the product for % f \ n ", s);
}
  • Related