Integer Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Integer.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept Recap
A data type that represents whole numbers (positive, negative, or zero) without decimal points.
Integers are counting numbers in code โ things you can count without fractions: age, score, quantity, index.
Read the full concept explanation โHow to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: Integers are exact and efficient. Use them for counting and indexing. Use floats/decimals when you need fractions.
Common stuck point: Integer division truncates in many languages: 7 / 2 gives 3, not 3.5. This catches many beginners by surprise.
Worked Examples
Example 1
easySolution
- 1 Step 1: Regular division: 17 \div 5 = 3.4.
- 2 Step 2: Integer division (floor): 17 \text{ DIV } 5 = 3 (discard the decimal part).
- 3 Step 3: Modulo: 17 \text{ MOD } 5 = 2 (the remainder after dividing 17 by 5).
Answer
Example 2
mediumPractice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
easyExample 2
mediumRelated Concepts
Background Knowledge
These ideas may be useful before you work through the harder examples.