39.1k views
4 votes
What will be the value of “sumtotal” when this code is executed?

int n1 = 3, n2 = 6, n3 = 2, sumtotal = 4;

if (n1 ! = 4)

sumtotal -= n3;

else if (n3 <= 5)

sumtotal = ++n2;

else sumtotal += n1;

1 Answer

3 votes

Answer:

2

Step-by-step explanation:

if-else is the statement that is used for checking the condition and if the condition is True, then execute the statement otherwise not executed.

initially, the value of n1 = 3, n2 = 6, n3 = 2, sumtotal = 4.

after that, if statement checks for the condition.

3 != 4

condition is TRUE, then the statement sumtotal -= n3; will be executed.

write the statement in simple form:

sumtotal = sumtotal - n3;

so, sumtotal = 4-2 = 2.

after that, the program does not check the further and exit the if-else statement.

Therefore, the answer is 2.

User Alyawn
by
6.6k points