in Programming in C edited by
447 views
1 vote
1 vote

How many times does the while loop gets executed if the following function is called as $f(120,13)?$ 

f(m,n) { ans := 1 
while (m - n >= 0) { 
ans := ans * 2 
m := m - n 
} 
return(ans)
}

 

in Programming in C edited by
447 views

3 Comments

ans$=512$ and while loop executed $9$ times
1
1
Please explain
0
0
edited by
ok please, you can also try to trace out.

check the answer
0
0

2 Answers

1 vote
1 vote
Best answer

Making a tree diagram is easy to understand.

edited by
0 votes
0 votes
Just 120/13=9.23 just take floor value which is 9 answer