int myFunction(int n) { int x = n * 2; int y = (x + 1) % 3; return y - x; } what does myFunction(5) evaluate to? what does myFunction(4) evalute to?
Answers
Answered by
6
In function, int myFunction(int n),
If n = 5, it evaluates to -8, as,
> x = n * 2
> x = 5 * 2
> x = 10
> y = (x + 1) % 3
> y = (10 + 1) % 3
> y = 11 % 3
> y = 2
Finally, y - x,
> 10 - 2
> -8
If n = 4, it also evaluates to -8, as,
> x = n * 2
> x = 4 * 2
> x = 8
> y = (x + 1) % 3
> y = (8 + 1) % 3
> y = 9 % 3
> y = 0
Finally, y - x,
> 0 - 8
> -8
Similar questions