Description
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.
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
Into the Wild
by Jon Krakauer
Fast Food Nation
by Eric Schlosser
Hidden Figures
by Margot Lee Shetterly
Team of Vipers
by Cliff Sims
One Flew Over the Cuckoos Nest
by Ken Kesey
Principles - Life and Work
by Ray Dalio
Gone with the Wind
by Margaret Mitchell
The Power of Habit - Why We Do What We Do in Life and Business
by Charles Duhigg
Dracula
by Bram Stoker