#!/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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.