Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
hi all i wrote this function to check if the number is prime or not but i just want to confirm if i'm doing this correctly
:
sub isPrime($) { $num = shift; my ($i,$c); for ($i = 1; $i < $num / 2; $i++) { if ($num % $i == 0){$c += 1;} } if ($c == 1){return 1;} return 0; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: is it prime?
by JavaFan (Canon) on May 06, 2012 at 05:39 UTC | |
by Anonymous Monk on May 06, 2012 at 05:44 UTC | |
by Anonymous Monk on May 06, 2012 at 05:54 UTC | |
by Anonymous Monk on May 06, 2012 at 05:57 UTC | |
Re: is it prime?
by tobyink (Canon) on May 06, 2012 at 06:19 UTC | |
Re: is it prime?
by johngg (Canon) on May 06, 2012 at 12:15 UTC | |
by JavaFan (Canon) on May 06, 2012 at 15:12 UTC | |
by tobyink (Canon) on May 06, 2012 at 19:41 UTC | |
by johngg (Canon) on May 09, 2012 at 09:33 UTC | |
by danaj (Friar) on Jun 09, 2014 at 08:57 UTC | |
Re: is it prime?
by 2teez (Vicar) on May 06, 2012 at 07:25 UTC | |
Re: is it prime?
by brx (Pilgrim) on May 06, 2012 at 14:21 UTC | |
by ambrus (Abbot) on May 06, 2012 at 17:32 UTC | |
Re: is it prime?
by Anonymous Monk on May 06, 2012 at 21:57 UTC |
Back to
Seekers of Perl Wisdom