Question

Consider the following pseudocode function. function Crunch(x is in R) if x ≥ 100 then return x/100 else return x + Crunch(10 · x) Compute Crunch(117).

Discrete math
ANSWERED
asked 2020-12-31

Consider the following pseudocode function. function Crunch\(\displaystyle{\left({x}\ {i}{s}\in{R}\right)}{\quad\text{if}\quad}{x}≥{100}\) then return x/100 else return \(x + Crunch(10 \cdot x)\) Compute Crunch(117).

Answers (1)

2021-01-01

Given
Crunch (x is in R)
if \(\displaystyle{x}\Rightarrow{100}\) then
returen \(\displaystyle\frac{{x}}{{100}}\)
else return \(x+\)Crunch \(\displaystyle{\left({10}\cdot{x}\right)}\)
We need to compute Crunch(117)
\(x=117\)
Since 117 is at least 100, we need to execute the then-statement "return \(\displaystyle\frac{{x}}{{100}}\)" and thus we need to divide the input \(x=117\) by 100:
\(\displaystyle\frac{{x}}{{100}}=\frac{{117}}{{100}}={1.17}\)
Thus Crunch \((117)=1.17\)

0
 
Best answer

expert advice

Need a better answer?
...