Computer Science, asked by sahejbir1998pduy0v, 1 year ago

What is the value of h(231,8) for the function below? def h(m,n): ans = 0 while (m >= n): (ans,m) = (ans+1,m-n) return(ans)

Answers

Answered by Shaizakincsem
0

n = 8, and for each iteration, n is deducted by 2, which means the loop would run 4 times, each for values of n = 8, 6, 4, 2.  

m = 6. The variable ans is multiplied by m for each iteration, i.e.

1*6*6*6*6

= 1296.

Here we see that the loop will run until n>o ,i.e,8>0..this will happen if the loop runs for 4 times.hence for each iteration the value 6 which is obtained as (ans*m=6) will be multiplied making the answer as 6*6*6*6*1=1296


Answered by mindfulmaisel
2

"The value of h(231,8) for the function below is 28.  def h(m,n): ans = 0 while (m >= n): (ans,m) = (ans+1,m-n) return(ans)

When executed , the while loop is iterated 28 times, as the initial value is 231 , it is 231 greater than or equal to 8. Hence it is (u, 231) = (1,223) and next step (1,223) = (2, 215). Similarly it executed for 28 times till it reaches less than 8.  

"

Similar questions