18 votes 18 votes 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 $\lfloor\sqrt N \rfloor$ $\lfloor\sqrt N \rfloor +1$ $\lceil \sqrt N \rceil$ $\lceil \sqrt N \rceil +1$ None of the above Algorithms gate1991 algorithms easy identify-function multiple-selects + – Kathleen asked Sep 12, 2014 edited Apr 17, 2021 by Lakshman Bhaiya Kathleen 3.5k views answer comment Share Follow See 1 comment See all 1 1 comment reply Manu Thakur commented Dec 24, 2017 reply Follow Share 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. 10 votes 10 votes Please log in or register to add a comment.
Best answer 19 votes 19 votes For $N=9$, it returns $3$. For $N=10$ it returns $4$. For $N=16$ it returns $4$. For $N=17$ it returns $5$. So answer should be C. Purple answered Jan 23, 2016 edited Oct 29, 2017 by kenzou Purple comment Share Follow See all 9 Comments See all 9 9 Comments reply ankyAS commented Dec 15, 2016 reply Follow Share I think answer is B. check for n=1 answer is 2 0 votes 0 votes Purple commented Dec 15, 2016 reply Follow Share I think it returns 1. 0 votes 0 votes ankyAS commented Dec 15, 2016 reply Follow Share yes i missed it and assumed it to be greater than and equal to. Thanks 0 votes 0 votes lU$er commented Dec 16, 2016 reply Follow Share 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. 0 votes 0 votes sushmita commented Apr 10, 2017 reply Follow Share 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 2 votes 2 votes sushmita commented Apr 15, 2017 reply Follow Share 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 votes 1 votes lU$er commented Apr 15, 2017 reply Follow Share I misinterpreted.. Thanks, point cleared and noted! :D 1 votes 1 votes srestha commented Jun 27, 2019 reply Follow Share i*i<M line is important ,if it will be. $\leq$ ns will be B) 0 votes 0 votes Vink7389 commented Sep 7, 2020 reply Follow Share How did you solve it??Plz explain step by step. 0 votes 0 votes Please log in or register to add a comment.
2 votes 2 votes The function returns $\lfloor \sqrt{N} \rfloor +1$. For $17$ it returns $5$, and for $16$ also it returns $5$. Rajarshi Sarkar answered Apr 21, 2015 Rajarshi Sarkar comment Share Follow See all 5 Comments See all 5 5 Comments reply Show 2 previous comments bad_engineer commented Sep 1, 2016 reply Follow Share For N=9, it returns 3. So it should Option C I think 2 votes 2 votes vishalshrm539 commented Dec 9, 2017 reply Follow Share for 16, it will return 4 not 5 0 votes 0 votes Aakash_ commented Sep 20, 2018 reply Follow Share No, suppose N = 16, condition will become false for i=4 as 4*4 is equal to 16, so the function will return 4, but according to your answer it'll be 5. only one option is correct (C) 0 votes 0 votes Please log in or register to add a comment.