edited by
304 views
0 votes
0 votes

Consider the following program. Assume that all variables are integers. Note that $x\%y$ computes the remainder after dividing $x$ and $y$. The division is an integer division. For example, $1/3$ will return zero while $10/3$ will return $3$.

g(n)
{
    result = 0;
    i = 1;
    repeat until(n == 0)
    {
        remainder = n%2;
        n = n/2;
        result = result+(remainder*i);
        i = i * 10;
    }
    return result;
}

What is $g(25)?$

  1. $11001$
  2. $10011$
  3. $11011$
  4. $10101$
edited by

1 Answer

0 votes
0 votes
Solution: (A) is correct. This code converts any given integer to its binary representation.25 is 11001 in binary.
Note: This question had a minor typographical error in the actual exam paper. This has been
taken into account when evaluating the question.
Answer:

Related questions

0 votes
0 votes
1 answer
1
soujanyareddy13 asked Jan 29, 2021
259 views
Consider the matrices$A=\begin{pmatrix} 0 & 0 & 0 & 0 & 15 \\ 0 & 0 & 0 & 13 &14 \\ 0 & 0 & 10 & 11 & 12 \\ 0 & 6 & 7 & 8 & 9 \\ 1 & 2 & 3 & 4 & 5 \end{pmatrix} \text{ an...
0 votes
0 votes
1 answer
3