Home > Back-end > This is a just began to learn C language course of small white help, falls for bosses to save the gi
This is a just began to learn C language course of small white help, falls for bosses to save the gi
Time:10-08
My teacher asked us to use an array to output the number of ten of the largest number, as shown in figure is my program, every time is the output of the last input number , strives for the bosses guide
CodePudding user response:
Behind your if statements with a semicolon, this creates the if I became a a statement has no effect, so you remove the if the back of the semicolon can
CodePudding user response:
If and for statement with a brace is bad?
CodePudding user response:
As friends upstairs said,
if (a [I] & gt; Max);
Instead of
if (a [I] & gt; Max)
Below are the results to debug
If it is
if (a [I] & gt; Max);
, the above is a statement, the loss of the characteristics of the if statement, which is to say, no matter a [I] & gt; Max values are true or false, will perform
Max=a, [I].
, so, no matter what is your input
Max=a, [I].
will be executed nine times, namely the Max value is always the last one input values,
CodePudding user response:
# include & lt; Stdio. H> # define N 10 Int main (int arg c, char * argv []) { Int I, a, [N]. Printf (" please enter the ten integer: \ n "); For (I=0; I<10; I++) { The scanf (" % d ", & amp; A [I]); } Int Max=a, [0]. For (I=1; I<10; I++) { If (a [I] & gt; Max) { Max=a, [I]. } } Printf (" the biggest number is % d \ n ", Max). return 0; }