+ 1
Just ran into this C++ question and needed help understanding it. Please help
The code is written down below. I know the answer is 10 but I couldn't find out why it is so. Int a= 10, b; B=a%(a+(a+1)/a); Cout<<b;
4 Respostas
+ 5
Its the operator precedence in the expression. In the 2nd line,the brackets are evaluated first,which is followed by division operation and then addition. So,the evaluation is done as follows:
10%(10+(10+1)/10)
=10%(10+(11)/10)
=10%(10+1)
=10%11
=10
Hence, b=10;
+ 4
Just pedantically saying that you should have used a lower case b and cout rather than Cout.
+ 3
1. (a + 1) / a = 11 / 10 = 1
2. a + (a + 1) / a = a + 1 = 11
3. a % (a + (a + 1) / a) = 10 % 11 = 10
+ 2
Thanks guys!