Home > Back-end >  To solve the
To solve the

Time:12-16

The second empty is why

CodePudding user response:

Carried out by an equal sign is the assignment, to have to zero,

CodePudding user response:


Int main (int a, char * * STR)
{
Int x=2, y=12, z=6;
While (x!=y)
{
X++; Z++; Y -;
}
Printf (" \ n z=% d ", z);

X=2; Y=12; Z=6;
While (x=y)
{
X++; Z++; Y -;
}
Printf (" \ n z=% d ", z);

}


Results:

CodePudding user response:

Q1: z=11
-- -- -- -- -- -- -- -- -- --
X=12 y=12 z=6
X=y=11 November z=7
X=10 y=10 z=8
9 x=y=9 z=9,
8 x=y=8 z=10
7 x=y=7 z=11
X=6 y=6 z=12
X=5 y=5 z=13
X=4 y=4 z=14
X=3 y=3 z=15
X=2 y=2 z=16
X=1 y=1 z=17
Q2: z=18

CodePudding user response:

The code is this:
Int main (int a, char * * STR)
{
Int x=2, y=12, z=6;
While (x!=y)
{
X++; Z++; Y -;
}
Printf (" Q1: z=% d \ n -- -- -- -- -- -- -- -- -- -- \ n ", z);

X=2; Y=12; Z=6;
While (x=y)
{
Printf (" x=y z==% d % d % d \ n ", x, y, z);
X++; Z++; Y -;
}

Printf (" Q2: z=% d \ n ", z);

}

CodePudding user response:

Because of the judgment is x=y; Expression, the expression for the false exit the loop, and false to 0, namely is y=0 is the cycle of exit criteria, so that's y=12 cycle 12 times, namely z +=12; The 18

Pay attention to x=y here is the assignment, exit ~ y final decision while loop
  • Related