Saturday, August 6, 2016

Prime Numbers in Perl

A simple program that I wrote using Perl  to display prime numbers at the screen.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing

#prime.pl

 my @prime_display;

for my $i (2..100){

    my $check="true";
    for (2..$i-1){
       if($i % $_ ==0){
          $check = "false"; 
       }
    }

    if ($check eq "true"){
       push @prime_display, $i;
    }
}
    print "\n\n";
    print "\tPrime Numbers Program in Perl";
    print "\n\n";
    print "List of Prime Numbers";
    print "\n\n";
    print "@prime_display.\n";
    print "\n\n";
    print "\t End of Program";
    print "\n\n";
   


No comments:

Post a Comment