Arithmetic Worksheet

For each of the following assignment statements, show the value that will be stored in the variable on the left hand side. Assume that you are given the following declarations:

   int num;
   float val;

   1.  num = 17 / 2 + 4;

   2.  val = 17 / 2 + 4;

   3.  num = 17 / 2.0 + 4;

   4.  val = 17 / 2.0 + 4;

   5.  num = 11 % 6 / 2 - 1;

   6.  val = 11 % 6 / 2.0 - 1;

   7.  num = 3 - (5 + 10 / (2 * 2));

   8.  val = 3 - (5 + 10 / (2 * 3.0));

   9.  val = 4.5 * (5 - 3);
       num = val;

   10. num = 15 / 2 % 3 - 1;

   11. num = 7 * 2 - 5 / 3;
       val = num;

Assume that total, num1, and num2 are int variables, with total = 2,
num1 = 3, and num2 = 4. Show the new values of all variables changed
by each of the following:

   12. total = ++num1;

   13. total = num2++;

   14. total *= 5;

   15. total += num1 - num2 * 4;

   16. total = ++num1 + num2++;

   17. total += 3 * num1++ - 5;


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2002