303,346 views
22 votes
22 votes
What is the value of sum after the code segment is executed?

What is the value of sum after the code segment is executed?-example-1
User Eleonor
by
2.7k points

2 Answers

16 votes
16 votes

Answer:

C: 16

Step-by-step explanation:

num1 < num2 is false since 6 < 4 is false.

Else, num3 = num2, which means both num3 and num2 have the value 4.

Then, it is checked if num2 >= num3. This is true because num2 (4) and num3 (4) have the same value. Therefore, num1 = num2 + num3, meaning that num1 is 4 + 4 = 8.

So, after all if statements, we have:

num1 = 8

num2 = 4

num3 = 4

sum is equal to num1 + num2 + num3 which is 8 + 4 + 4 = 16.

User Thomas Billet
by
2.9k points
13 votes
13 votes

Answer:

16

Step-by-step explanation:

Following the code segment:

num1 = 6

num2 = 4

num3 = 10

IF num1 < num2 (which is FALSE as 6 > 4) THEN....ELSE num3 = num2 = 4

IF num2 >= num3 (which is TRUSE as 4 = 4) THEN num1 = num2 + num4 = 4 + 4 = 8

sum = num1 + num2 + num3 = 4 + 4 + 8 = 16

User Rafa Paez
by
2.6k points