This c++ code prints out the following prime numbers: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97.
But I don\'t think tha
I did it in perl based on the most popular answer by ProdigySim's 2nd method. I had to add a break equivalent in perl, last, right after the print $i . " \n"; to avoid outputting the primes twice.
#!/bin/perl
use strict;
for(my $i=2; $i < 100; $i++){
my $prime = 1;
for (my $j=2; $j*$j<=$i; $j++){
if ($i % $j == 0){
$prime = 0;
last;
}
if($prime) {
print $i . " \n";
last;
}
}
}