Home > Back-end >  Logic is a little small problem,
Logic is a little small problem,

Time:10-10

#include
Int main ()
{
Int a=0; int b=0; int c=0;//two variables
Int m;//m variables
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);//to a and b assignment
M=a & gt; B & amp; & A. & lt; C;//condition operation if a=5, b=3, c=6 output should be m=1 why is 0
Printf (" m=% d ", m);//output



return 0;
}


CodePudding user response:

The format of the input is wrong, because the scanf "" there is, between each input comma (pay attention to the comma in the English and Chinese to the scanf consistent).

CodePudding user response:

#include
Int main ()
{
/* int a=0, b=0, c=0;
Int m=0;
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);
M=(a + b), (c * a);
Printf (" m=% d ", m);

*/
Int a=2, b=4, c=6, x, y;
Y=(a + b), (b + c);
Printf (" y=% d, x=% d \ n ", x, y);
Return 0;
}
Run results y=8, x=6, mentally, and clearly according to the second expression for the final result, comma expression to calculate a + b=6, b + c=10, why poor results so far,,,
Hope to have a passing friend, understand, help solve, thank you!
I a person self-study reading, some points still don't understand,

CodePudding user response:

reference 1/f, confident boy reply:
the format of the input is wrong, because the scanf "" there is, between each input comma (note the comma in the English and Chinese to the scanf consistent),


Thank you, but I just try again,
If or not the results or
M=0

CodePudding user response:

Y=(a + b), (b + c); This a comma operator on the left is an expression, the right to an expression, y=(a + b) and (b + c), so y=6, if it is y=((a + b), (b + c)); This is x, y=10, because temporary variables and no initialization, x in stack space, its value is a garbage value in memory

CodePudding user response:

The building Lord why not add parentheses??

CodePudding user response:

refer to the second floor tomorrow will reply: D
# include
Int main ()
{
/* int a=0, b=0, c=0;
Int m=0;
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);
M=(a + b), (c * a);
Printf (" m=% d ", m);

*/
Int a=2, b=4, c=6, x, y;
Y=(a + b), (b + c);
Printf (" y=% d, x=% d \ n ", x, yprintf (" y=% d, x=% d \ n ", x, y); return 0;
}
Run results y=8, x=6, mentally, and clearly according to the second expression for the final result, comma expression to calculate a + b=6, b + c=10, why poor results so far,,,
Hope to have a passing friend, understand, help solve, thank you!
I a person self-study reading, some points still don't understand,


This number on to? Can not be?
 
Printf (" y=% d, x=% d \ n ", x, y);

The value of y=x, x=y values

CodePudding user response:

refer to the second floor tomorrow will reply: D
# include
Int main ()
{
/* int a=0, b=0, c=0;
Int m=0;
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);
M=(a + b), (c * a);
Printf (" m=% d ", m);

*/
Int a=2, b=4, c=6, x, y;
Y=(a + b), (b + c);
Printf (" y=% d, x=% d \ n ", x, y);
return 0;
}
Run results y=8, x=6, mentally, and clearly according to the second expression for the final result, comma expression to calculate a + b=6, b + c=10, why poor results so far,,,
Hope to have a passing friend, understand, help solve, thank you!
I a person self-study reading, some points still don't understand,


Comma expression need to add brackets x=(p1, p2, p3)
Your program change y=((a + b), (b + c));

CodePudding user response:

The
references 4 floor of the deep is also make a reply:
y=(a + b), (b + c); This a comma operator on the left is an expression, the right to an expression, y=(a + b) and (b + c), so y=6, if it is y=((a + b), (b + c)); This is x, y=10, because temporary variables and no initialization, x in stack space, its value is the memory of a garbage value


Thank you friends, understand the

CodePudding user response:

reference 6 building self-confidence boy reply:
Quote: refer to the second floor tomorrow will reply: D
# include
Int main ()
{
/* int a=0, b=0, c=0;
Int m=0;
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);
M=(a + b), (c * a);
Printf (" m=% d ", m);

*/
Int a=2, b=4, c=6, x, y;
Y=(a + b), (b + c);
Printf (" y=% d, x=% d \ n ", x, yprintf (" y=% d, x=% d \ n ", x, y); return 0;
}
Run results y=8, x=6, mentally, and clearly according to the second expression for the final result, comma expression to calculate a + b=6, b + c=10, why poor results so far,,,
Hope to have a passing friend, understand, help solve, thank you!
I a person self-study reading, some points still don't understand,


This number on to? Can not be?
 
Printf (" y=% d, x=% d \ n ", x, y);

The value of y=x, x=y


I careless, oneself ability does not pass, as a result, operation results, thank you for your found!

CodePudding user response:

5250 reference 7 floor response:
Quote: refer to the second floor tomorrow will reply: D
# include
Int main ()
{
/* int a=0, b=0, c=0;
Int m=0;
The scanf (" % d, % d, % d ", & amp; A, & amp; B, & amp; C);
M=(a + b), (c * a);
Printf (" m=% d ", m);

*/
Int a=2, b=4, c=6, x, y;
Y=(a + b), (b + c);
Printf (" y=% d, x=% d \ n ", x, y);
return 0;
}
nullnullnullnullnullnullnull