Practice Problems with Operations

For the following questions, suppose we have these variables:

         INTEGER :: A = 17, B = -3, C
         REAL :: X = 4.2, Y = 1.9, Z
         CHARACTER(5) P = 'OLIVE'
         CHARACTER(6) Q = 'PEPPER'
  1. Find the value of each of these arithmetic expressions.
    1. A * 2 + B / 3

    2. A * (2 + B) / 3

    3. B ** 2 / (A - 8)

    4. B ** 2 / A - 8

    5. B * Y

    6. X + MOD(A, 5)

    7. 5 ** (B + 2.0)

    8. 5 ** B + 2.0

  2. These have to do with assignment statements.
    1. Suppose we have this statement: C = X + Y

      What value is in C?

    2. Suppose we have this statement: Z = A / 4 + A / 4.0

      What value is in Z?

    3. Suppose we have this statement: C = X / 5 + Y * 2

      What value is in C?

    4. Suppose we have this statement: Z = 4.0 + B * Y

      What value is in Z?

  3. Find the value of each of these logical expressions.
    1. (X .GT. 4)

    2. ((Y .LE. 2) .OR. (-6 * B .GE. A))

    3. ((X + Y < 7) .AND. (MOD(B, 3) .EQ. 0))

    4. ((A .LT. 4 * X) .EQV. (Y .GT. B * 2 / -3))

    5. ((B + Y .GE. -2) .NEQV. (A - X .LT. 13))

  4. Find the value of each of these character expressions.
    1. Q(3:4)

    2. P // 'OYL'

    3. Q(1:1) // P(1:1) // Q(2:6)

    4. P(2:5) // Q(3:6)