Y = Coin Piece, X = Money To Change, Data are number of coins needed."; echo "\n"; // display the change value as a header for the table for ($k=100; $k>0; $k--) { echo ""; } echo "\n"; for ($coin=1; $coin<101; $coin++) { // for each coin size... // reset the number for averages $total = 0; echo ""; if ( (($coin-1)%10 == 0) && ($coin > 8) ) { echo ""; // display the change value as a header for the table for ($k=100; $k>0; $k--) { echo ""; } echo "\n"; } if ( ($coin == $penny) || ($coin == $nickle) || ($coin == $dime) || ($coin == $quarter) ) { echo ""; } else { echo ""; } $count = 0; for ($money=100; $money>0; $money--) { // and for each MONEY AMOUNT... echo " "; $coins = 0; $denom = array($penny, $nickle, $dime, $quarter, $coin); rsort($denom); // LARGEST DENOM while ($money >= $denom[0]) { $money = $money - $denom[0]; $coins++; } while ($money >= $denom[1]) { $money = $money - $denom[1]; $coins++; } while ($money >= $denom[2]) { $money = $money - $denom[2]; $coins++; } while ($money >= $denom[3]) { $money = $money - $denom[3]; $coins++; } while ($money >= $denom[4]) { $money = $money - $denom[4]; $coins++; } if ($coins == 1) { echo ""; } else { echo ""; } $total = $total + $coins; $money = 100 - $count; $count++; } $average = $total / 100; $averages[$coin] = $average; echo "\n"; } echo "
 $k
 $kAverages
$coin
$coin$coins$coins$average
"; ?>

Most Efficient

"; asort($averages); echo "
";
print_r($averages);
echo "
"; ?>

Conclusions

With our current common coinage (excluding half and whole dollars), the current average number of coins needed when making change is 4.74. If we introduced a 2¢ or 3¢ piece, the average number of coins would drop to 3.94 coins. That's a drop of almost an entire coin!