229k views
2 votes
What is the output of the following code?

int x = 6, y = 3, z=24, result=0;

result = 2*((z/(x-y))%y+10);

cout<< result<

User Ruturaj
by
5.9k points

1 Answer

7 votes

Answer:

The output is 24

Step-by-step explanation:

Given

The above code segment

Required

The output

We have (on the first line):


x = 6


y = 3


z=24


result=0

On the second line:


result = 2*((z/(x-y))\%y+10)

Substitute the value of each variable


result = 2*((24/(6-3))\%3+10)

Solve the inner brackets


result = 2*((24/3)\%3+10)


result = 2*(8\%3+10)

8%3 implies that, the remainder when 8 is divided by 3.

The remainder is 2

So:


result = 2*(2+10)


result = 2*12


result = 24

Hence, the output is 24

User Pritesh Agrawal
by
6.2k points