Practice Integer in CS Thinking
Use these practice problems to test your method after reviewing the concept explanation and worked examples.
Quick 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.
Example 1
easyWhat is the result of integer division 17 \div 5 and 17 \mod 5? Explain the difference from regular division.
Example 2
mediumA program stores a student's age as an integer. Why would an integer be more appropriate than a floating-point number for age in years?
Example 3
easyWhat are the results of: (a) 25 MOD 7, (b) 100 DIV 3, (c) 8 MOD 2?
Example 4
mediumA vending machine program stores the price as 175 (meaning $1.75 in cents). A customer inserts 200 cents. Using only integer arithmetic (DIV for integer division, MOD for remainder), calculate the change in dollars and remaining cents.