Q:

Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same thing. Assume that num is an integer variable that has been initialized, and that there are functions f1, f2, f3, and f4

0

 Rewrite the following nested if-else statement as a switch statement that accomplishes exactly the same thing. Assume that num is an integer variable that has been initialized, and that there are functions f1, f2, f3, and f4. Do not use any if or if-else statements in the actions in the switch statement, only calls to the four functions.

if num < -2 || num > 4

f1(num)

else

if num <= 2

if num >= 0

f2(num)

else

f3(num)

end

else

f4(num)

end

end

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch4Ex24.m

% To run this, would need to create functions

switch num

 case {-2, -1}

 f3(num)

 case {0, 1, 2}

 f2(num)

 case {3, 4}

 f4(num)

 otherwise

 f1(num)

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now