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 stored exactly in memory and support arithmetic operations like addition, subtraction, multiplication, and integer division.

Integers are counting numbers in code โ€” things you can count without fractions: age, score, quantity, index.

Showing a random 20 of 50 problems.

Example 1

easy
What are the results of: (a) 25 MOD 7, (b) 100 DIV 3, (c) 8 MOD 2?

Example 2

medium
Compute `-7 % 2` in Python (result takes the sign of the divisor).

Example 3

hard
For arrays of length 7, what is the wrap-around index of โˆ’1โ€Šmodโ€Š7-1 \bmod 7 in Python?

Example 4

medium
Trace: `n = 17`. Compute `n // 10` and `n % 10`. What are they?

Example 5

medium
A signed 8-bit integer ranges from โˆ’128-128 to 127127. How many distinct values does it represent?

Example 6

medium
Trace: n=256n = 256. Compute n//16n // 16 and nโ€Šmodโ€Š16n \bmod 16.

Example 7

medium
A program uses integers in cents to store dollars. \$3.47 is stored as what integer?

Example 8

easy
Compute `5 * 4` (integer multiplication).

Example 9

medium
Trace: n=365n = 365. Compute weeks and leftover days as n//7n // 7 and nโ€Šmodโ€Š7n \bmod 7.

Example 10

medium
Compute the last digit of `1234` using modulo.

Example 11

medium
Convert 125 seconds to minutes and seconds using integer arithmetic.

Example 12

easy
Fill in: nโ€Šmodโ€Š2=0n \bmod 2 = 0 means nn is ___.

Example 13

medium
Convert 90 minutes to hours and minutes using `//` and `%` with 60.

Example 14

medium
A 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.

Example 15

easy
Compute 15//415 // 4 (integer division).

Example 16

medium
Use modulo to wrap an index: with array length 5, what is index `7 % 5`?

Example 17

medium
Compute `-7 // 2` in Python (floor division rounds toward negative infinity).

Example 18

hard
Trace a loop: n=13n = 13; while n>0n > 0: print nโ€Šmodโ€Š2n \bmod 2; n=n//2n = n // 2. What sequence is printed?

Example 19

easy
True or false: 00 is an integer.

Example 20

challenge
How many trailing zeros does 10001000 have in base 10, computed using repeated โ€Šmodโ€Š10\bmod 10?