+ 1
Please help for this equation in c++
Input (7%6)/2*5 output: 0 how? Please answer...
7 ответов
+ 8
S.k. techno point ok, anyway, maybe, the question is not complete
+ 7
1. 7%6 is remainder when dividing 7 to 6 that is 1
2. 1/2=0.5
3. 0.5*5=2.5
It seems like your output must be an integer so 2.5 becomes 2
I hope it was useful:)
+ 3
S.k. techno point Oh, in your question I thought you said the output is 2. In my answer the note at the bottom is wrong I guess. When it divides 1 by 2 in integer division, it would return 0 and then 0 * anything is 0.
+ 2
By the order of operations, parentheses come first, so the equation is now 1/2*5 (7%6 = 1 remainder 1, mod is the remainder, so returns 1). Since the operators are now at the same level, they are executed left to right. First 1/2, which is 0.5, then 0.5*5, which is 2.5. Now since this is integer division (there are no floats or dou les in the original inputted expression) the decimal is discarded, leaving 2.
Note: the decimal is only removed at the end, so 0.5 isn't turned to 0 mid-evaluation causing 0 as the answer.
+ 1
But the answer comes out to be 0 when I run it.
+ 1
Ook... thanks...
+ 1
Zhenis Otarbay there was an error in the question kindly check it again please...