One subtraction, then largest first
The arithmetic is one subtraction: change due equals amount tendered minus purchase total. The tool then walks the denomination list - $100, $50, $20, $10, $5, $1, 25c, 10c, 5c, 1c - and for each one subtracts as many copies as fit without going negative. In the US system this largest-first rule is provably optimal, so the piece count shown is the true minimum, not just a convenient habit.