#!/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";
In reply to Calculate primes! by azerton
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |