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 Show 6 previous comments 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.