Q:

What would be the output from the following program? Think about it, write down your answer, and then type it in to verify

0

 What would be the output from the following program? Think about it, write down your answer, and then type it in to verify. 

All Answers

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

testscope.m

answer = 5;

fprintf('Answer is %d\n',answer)

pracfn

pracfn

fprintf('Answer is %d\n',answer)

printstuff

fprintf('Answer is %d\n',answer)

pracfn.m

function pracfn

persistent count

if isempty(count)

 count = 0;

end

count = count + 1;

fprintf('This function has been called %d times.\n',count)

end

printstuff.m

function printstuff

answer = 33;

fprintf('Answer is %d\n',answer)

pracfn

fprintf('Answer is %d\n',answer)

end

>> testscope

Answer is 5

This function has been called 1 times.

This function has been called 2 times.

Answer is 5

Answer is 33

This function has been called 3 times.

Answer is 33

Answer is 5

>>

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