anonymous
  • anonymous
Consider the following pseudocode function. function Crunch(x is in R) if x ≥ 100 then return x/100 else return x + Crunch(10 · x) (a) Compute Crunch(5). Crunch(5) =
Mathematics
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
@e.mccormick
anonymous
  • anonymous
(b) What happens if you try to compute Crunch(−23)? What does this suggest about an appropriate precondition for this function?
zzr0ck3r
  • zzr0ck3r
crunch(5) since x is not >= 100 return x + Crunch(10 · x) = 5+crunch(10*5) = 5+crunch(50) crunch 50 will return 50+crunch(50*10) so we have 5+50+crunch(500) crunch 500 will return 500/100 = 5 so crunch(5) returns 5+50+5 = 60

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

zzr0ck3r
  • zzr0ck3r
I think
zzr0ck3r
  • zzr0ck3r
Crunch(−23) will always crunch a number <= 100 so it will go in infinite loop, thus x needs to be positive
anonymous
  • anonymous
Consider the following pseudocode function. function Crunch(x is in R) if x ≥ 100 then return x/100 else return x + Crunch(10 · x) (a) Compute Crunch(5). Crunch(5) = |dw:1371433544740:dw|
zzr0ck3r
  • zzr0ck3r
do you get the same return as me @oldrin.bataku ?
zzr0ck3r
  • zzr0ck3r
do you understand what I did @malia667 ?
anonymous
  • anonymous
always helpful to plot the control flow graph. For \(x=5\), we observe \(5\not\ge100\) and therefore we now have \(Crunch(5)=5+Crunch(50)\). For \(x=50\), we observe \(50\not\ge100\) and therefore \(Crunch(5)=5+50+Crunch(500)\). For \(x=500\), we observe \(500\ge100\) and therefore \(Crunch(500)=5\) yielding \(5+50+5=60\)
zzr0ck3r
  • zzr0ck3r
ok good
anonymous
  • anonymous
For \(Crunch(x)\) where \(x\le 0\) we get stuck in an infinite loop since no matter how many times you multiply by \(10\) you'll always end up \(10^nx\le100\)!
anonymous
  • anonymous
100% correct @zzr0ck3r :-)
zzr0ck3r
  • zzr0ck3r
I realized when I starting typing that I have not done any coding so maybe I should keep my mouth shut.
anonymous
  • anonymous
I'm sure you'd be a great programmer! You're good at math so it's only natural
zzr0ck3r
  • zzr0ck3r
ditto
anonymous
  • anonymous
thank you! @zzr0ck3r
anonymous
  • anonymous
thank u @oldrin.bataku
anonymous
  • anonymous
good work @zzr0ck3r

Looking for something else?

Not the answer you are looking for? Search for more explanations.