Skip to main content 
 Contents  Index  Dark Mode  Prev  Up Next   \(\newcommand{\N}{\mathbb N}
\newcommand{\Z}{\mathbb Z}
\newcommand{\Q}{\mathbb Q}
\newcommand{\R}{\mathbb R}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle     \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle        \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle      \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\) 
Section   4.11   Division 
 
Get ready to be surprised. But don’t worry, we’ll explain everything soon!
Subsection   4.11.1   Intro to Division in C 
 
Activity   4.11 . 
 
Try to predict what the output of the following program will be:
admin ..... open in new window 
 Which of the following do you think will be printed to the screen?
 
5 / 3 = 1Correct! Do you have any idea why this might be happening?
5 / 3 = 1.666667Unfortunately, this is not what happens...
5 / 3 = 1.67Unfortunately, this is not what happens...
5 / 3 = 2Not quite - try again!
5 / 3 = 1.7Not quite - try again!
 
 
Subsection   4.11.2   Your Turn! 
 
Activity   4.12 . 
 
Click on the 
Run button in the window below to reveal the integer division behavior that C exhibits. Next, change the data types of some of the variables (use float instead of int) and observe the outcome. What do you notice?
admin ..... open in new window 
Summary of division behavior in C:. Following are the results of various examples of division in C. Notice the effect that the 
types  of numbers being divided have on the quotient. Are there patterns? Why is this happening?
5/2 = 2
 
 
5.0/2 = 2.5
 
 
5/2.0 = 2.5
 
 
5.0/2.0 = 2.5