edited by
3,472 views
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

  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
edited by

2 Answers

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.

edited by
2 votes
2 votes
The function returns $\lfloor \sqrt{N} \rfloor +1$. For $17$ it returns $5$, and for $16$ also it returns $5$.
Answer:

Related questions

21 votes
21 votes
1 answer
1
43 votes
43 votes
3 answers
2
Kathleen asked Sep 12, 2014
13,807 views
Kruskal’s algorithm for finding a minimum spanning tree of a weighted graph $G$ with $n$ vertices and $m$ edges has the time complexity of:$O(n^{2})$$O(mn)$$O(m+n)$$O(m...
25 votes
25 votes
5 answers
3
Kathleen asked Sep 12, 2014
4,260 views
The following sequence of operations is performed on a stack:$PUSH (10), PUSH (20), POP, PUSH (10), PUSH (20), POP, POP, POP, PUSH (20), POP$The sequence of values poppe...