Bot explanation


#1

what I can think of is, both C and D are performing the same functionality one is increasing while other is decreasing.

The factor that makes C correct answer is that we do a comparison till zero not -1 as in option D. As stated the input is +ve number. We would be comparing 1extra time in option D.
Open for healthy discussions.


#2

Hii,
The D option is an infinite loop, so C option is correct.
Explaination: See what is happening there, the input (n) is positive and when you divide a positive integer again and again by any number (here 2). The value becomes 0, so it never goes to negative part. Hence, the condition remains true after all iterations.
eg. n = 5
i = 5, 5 > -1(true), i becomes 2 (5/2 = 2)
i = 2, 2 > -1 (true), i becomes 1 (2/2 = 1)
i = 1, 1 > -1 (true), i becomes 0 (1/2 = 0)
i = 0, 0 > -1 (true), i becomes 0 (0/2 = 0)
i = 0, 0 > -1 (true), i becomes 0 (0/2 = 0) … and so on forming an infinite loop.


#3

Your ans. is correct but Explanation is a bit wrong. in D the loop is infinite as 0 gets divided by 2 infinite no. of times.