636 views

Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:

Consider the following Pascal function:

Function X(M:integer):integer;
Var i:integer;
Begin
i := 0;
while i*i < M
do i:= i+1
X := i
end



The function call $X(N)$, if $N$ is positive, will return

1. $\lfloor\sqrt N \rfloor$
2. $\lfloor\sqrt N \rfloor +1$
3. $\lceil \sqrt N \rceil$
4. $\lceil \sqrt N \rceil +1$
5. None of the above
0
Correct option should be either (B) or (C).
Option (B) is incorrect for the perfect squares.
if we consider option (B), for 4 answer will be 3, for 25 answer will be 6.

While option(C) gives correct answer always.

For $N=9$, it returns $3$.

For $N=10$ it returns $4$.

For $N=16$ it returns $4$.

For $N=17$ it returns $5$.

edited by
0

check for n=1 answer is 2
0
I think it returns 1.
0
yes i missed it and assumed it to be greater than and equal to.

Thanks
0
What is the difference between ceil(sqrt(N)) and floor(sqrt(N)) + 1 that is (B) and (C) ?

N=10 it returns 4.

sqrt(10) = 3.16

floor(3.16) + 1 = 4 (B) as well as ceil(3.16) = 4 (C)

I'm confused.
+1

ceil(X) will return x+1 when x is a decimal and not integer.

floor(x)+1 will add 1 even in case of integers, hence for N=4 it will give answer as 2+1=3. So wrong choice

+1
so u mean ceil(4) will return 5???

obviously ceil(sqrt()) will return 4 because ceil(3.xxx) will return 4. so what's wrong have i said
+1
I misinterpreted.. Thanks, point cleared and noted! :D
The function returns $\lfloor \sqrt{N} \rfloor +1$. For $17$ it returns $5$, and for $16$ also it returns $5$.
0
It will return integer part of sqrt(N)  I don't whether [sqrtN]  mean same
0
It should be for floor. Typo in question.
+1
For N=9, it returns 3.

So it should Option C I think
0
for 16, it will return 4 not 5