Assessment Tool
Lecture 4: Arithmetic Expressions
Content Tested: Int and Double Types, Arithmetic in C
Lecture Content:
-
Arithmetic expressions
-
Integer and floating-point (double) types
-
Unary and binary operators
-
Precedence
-
Associativity
-
Conversions and casts
-
Symbolic constants
Goals:
-
Understand associativity and precedence rules
-
Understand arithmetic on int and double types in C
Assessment Technique: Expression Exercises
Purpose:
This activity allows instructors to see if students understand how to simplify
arithmetic expressions in C.
Activity:
Simplify the following expressions (remember, these expressions are written
in the C language and may not follow conventional mathematical rules):
1. (15 / 2) * (3 / 2)
2. 15 * 3 / 2 / 2
3. 3 / 2 * 15 / 2
4. 15 / 2 * 3 / 2
5. (15 * 3)/(2 * 2)
6. (15.0 * 3) / 2
7. (int) (15.0 / 2.0)
8. 8 + 7 % 5 - 6
9. 6 - -3 * 50 % (48 + 9 / 8)
10. (double) 10 / 4
11. (double) (10 / 4)
12. (int) ((double) 10) / (double) 4 + 1.0
Solutions:
1. 7
2. 11
3. 7
4. 10
5. 11
6. 22.5
7. 7
8. 4
9. 9
10. 2.5
11. 2.0
12. 3.0 (The integer 2 is added to 1.0, so the result is
a double.)
Possible Uses of Activity:
-
Have students work in groups to complete this activity. The instructor
may want to circulate throughout the groups to ensure that each group is
making progress. After the groups have completed the problems, the
instructor can ask for volunteers for each problem. Be sure to ask
for explanations of the arithmetic.
-
Have students work individually on their problems and form a small group
to discuss their answers.