CS 231 Selected Solutions for Midterm


  1. See definitions on-line.

  2. a) (3+2)/(2*2) + 1.5 = 5/4 + 1.5 = 2.5

    b) 12/3 * 4 = 4*4 = 16

    c) not valid - x is not initialized

    d) .5/(4 % 5) = .5/4 = .125

  3. a) x = 6.0

    b) not valid - can't put a double into an int

    c) not valid - can't put a double into an int. Note that the (int) cast only applies to w and not z.

    d) not valid - incorrect syntax for cast. The word float needs to have parenthesis around it, e.g. z * (float) (2*n).

  4. You need not know how to do for this exam.

  5. 1 00011000 11000000000000000000000

    s = 1

    e = 000110002 = 3210,

    m = .110000000000000000000002 = 1/2 + 1/4 = .7510

    Thus the base 10 representation is (-1)1 * 1.75 * 224-127 = - 1.75 * 224-127 = -1.75 * 2-103