Skip to main content

Section 6.1 Review: Integer Division

Recall the funny division behavior we notice in the C programming language when using integers. Feel free to play around in this code window to refresh your memory and experiment in order to analyze this behavior.

admin.....open in new window

Check Your Understanding Check Your Understanding

1.

Here is a quick review question: Using integer arithmetic, what is the result of 15/4?
  • 3
  • Correct!
  • 4
  • Not quite - try again!
  • 3.75
  • Not quite - try again!
  • 0.75
  • Not quite - try again!
Hint.
In an integer division only the integer part of the result is accounted for.

2.

Another quick review question: In the C programming language, what is the result of 19/2.0?
  • 9.5
  • Correct!
  • 9
  • Not quite - try again!
  • 10
  • Not quite - try again!
  • 9R1
  • Not quite - try again!
Hint.
By writing 2.0 instead of 2 in the computation, the data type in which the operation is performed is automatically cast to a floating point which means that the result can also be a floating point number.

3.

And another review question: Suppose that a and b are variables of type int, a has the value 8, b has the value 6. In the C programming language, what is the value of (a+b)/3?
  • 4
  • Correct!
  • 5
  • Not quite - try again!
  • 4.6
  • Not quite - try again!
  • 4.67
  • Not quite - try again!
Hint.
Because of the data types of a and b, an integer division is performed here.