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

CodePudding user response:

refer to 1st floor @ big fool @ reply:
behind your if statements with a semicolon, this creates the if I became a no effect of a statement, so you remove the if the back of the semicolon is

God to the semicolon can?? C: it's very rigorous crab crab

CodePudding user response:

refer to the second floor effort2019 response:
if and for statement with a brace is bad?

Oh ~ I now know only int main and when there are two or more statements for back and if the back even if should have braces when other... Also in the study

CodePudding user response:

reference MianHou reply: 3/f
as upstairs friend 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,

Well well well next time to wear glasses!!!!!!
  • Related