We are given a C function, mystery() as follows.
void mystery(int m, int n)
Let X be the number of times the comparission inside the while loop ( i.e., m<=n ) is performed, when mystery(127,255) is called.
Then the value of X is _______________
I m getting 66 comparisons but ans given as 65..plz verify @Shaik Masthan @MiNiPanda
In each iteration, m will be increased by 1 and n will be decreased by 1 (also 1 comparison made).
So in k iterations, m will become (m+k) and n will become (n-k) (k comparisons made).
The last comparison made will be when (m+k)>(n-k).
As k>64 so at 65th iteration (65th comparison) m will become more than n.
After that at 66th iteration the while condition won't be satisfied. So 66 comparisons are needed.
The link where you tagged me few minutes back isn't accessible to me.