| Category: | Fun |
| Author/Contact Info | Azerton 2004 |
| Description: | This program will calculate primes for you. |
#!/usr/bin/perl
##################################
### To find the largest prime! ###
### by Azerton 2004 ###
##################################
system(clear);
#ASK FOR INPUT
print "Created by Azerton, 2004\n";
print "I will calculate the primes from 1 to the number you enter. Wha
+t is the maximum number to check?\n";
START:
$max=<STDIN>; #max value to calculate
if ($max<=1){
die "Negatives or 0 not allowed!\n";
}
$getal=$max+1; #I use this now
$teller=0; # A/B would give A in this case
$deeltal=2; # A/B would give B in this case
for ($max;$getal-=1;$getal>=0)
{
#$getal -=1; Check if it's a prime, by going down 1 value
$deeltal=2;
$teller=0;
while($getal % $deeltal!=0 && $deeltal+2<=$getal){
$teller+=1;
$deeltal+=1;
} #important while: closed
if($teller+3==$getal){
push(@priemlijst,$getal);
} else
{
#Don't you dare to do anything
} #We don't have a prime, too bad
} # Close main for
system (clear);
push(@priemlijst,2); #Don't forget number 2!
@priemlijst=reverse(@priemlijst); #Tidy the room
print "The primes from 1 to $max are : @priemlijst \n";
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calculate primes!
by Juerd (Abbot) on May 05, 2004 at 22:38 UTC | |
by azerton (Beadle) on May 06, 2004 at 21:36 UTC | |
|
Re: Calculate primes!
by Ovid (Cardinal) on May 05, 2004 at 16:19 UTC | |
|
Re: Calculate primes!
by Plankton (Vicar) on May 05, 2004 at 15:56 UTC | |
by Anonymous Monk on May 05, 2004 at 17:22 UTC | |
|
Re: Calculate primes!
by PERLscienceman (Curate) on May 06, 2004 at 02:03 UTC | |
|
Re: Calculate primes!
by QM (Parson) on May 05, 2004 at 21:25 UTC |