in reply to how to make perl only print whole numbers
That's why your code prints also fractional numbers - it never checks for integer divisibility.
One good way to do that is to use the % infix operator (modulus operation), which gives you the reminder of a division. So for example 7 % 3 is 1, because if you divide 7 by 3, the remainder is one. If the remainder is zero, the second number evenly divides the first.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to make perl only print whole numbers
by derpp (Acolyte) on Aug 03, 2010 at 22:30 UTC | |
|
Re^2: how to make perl only print whole numbers
by rowdog (Curate) on Aug 04, 2010 at 10:38 UTC | |
by SuicideJunkie (Vicar) on Aug 04, 2010 at 13:43 UTC |