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
3
i guess the answer is 28!! as the while loop will be running for 28 such times for that particular condition
Answered by
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
Similar questions
Social Sciences,
7 months ago
Chemistry,
7 months ago
Physics,
7 months ago
Business Studies,
1 year ago
Math,
1 year ago
English,
1 year ago