why the answer is 3??

What is the value of x after the following statements?

int x, y, z;

y = 10;

z = 3;

x = 3 + y * z;
output=====33
What is the value of x after the following statements?

int x;

x = 15 %4;
output====3

..thanks in advanced.................
What else do you expect from 15 % 3 (15 mod 3)? The remainder is 3.75 which is rounded down to 3 because the data type is an integer.
The % operator gives you the remainder of the division. https://en.wikipedia.org/wiki/Remainder

15 / 4 = 3 + 3 / 4
         ^   ^
         |   |
         |   3 is the remainder of the division
         |   To get this value in C++ use 15 % 4
         |
         3 is the number of times that 4 divides 15
         To get this value in C++ use 15 / 4
Last edited on
Because variable x is the wrong data type.
Because variable x is the wrong data type.

Incorrect.
1
2
3
4
5
15 / 4 = (3 * 4) + 3
4 divides 15 evenly 3 times.
3 times 4 equals 12.
12 plus 3 equals 15.
3 is the remainder.
Topic archived. No new replies allowed.