M

Manisha Agrawal • 9.34K Points
Tutor III

Q. What will be the output of the following code snippet?

Code:
#include <stdio.h>
void solve() {
    int n = 24;
    int l = 0, r = 100, ans = n;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(mid * mid <= n) {
            ans = mid;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }
    printf("%d", ans);
}
int main() {
    solve();
	return 0;
}
  • (A) 5
  • (B) 4
  • (C) 3
  • (D) 6

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics