Consider the following pseudocode function

User Generated

crgvgfba

Mathematics

Description

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Thank you for the opportunity to help you with your question!

a) crunch(5)=60

1st time it will go to else part = 5+crunch(5*10)

again crunch(50) function is executed

2nd time it will go to the else part= 5+ 50 +crunch(500)

again crunch(500) function is executed

since 500>100, it will return 500/100=5


total=5+50+5=60


b) crunch(-24)= will run for infinite times.

in the condition it is only if x>=100;

so every time it will go to the else part and get multiplied by 10, and still remain negative. hence it will not terminated.

precondition can be mod(x)>=100 will eliminate such errors.

Please let me know if you need any clarification. I'm always happy to answer your questions.


Anonymous
Goes above and beyond expectations!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags