CGI Perl Question:

Write a script to generate n prime no.s?

Tweet Share WhatsApp

Answer:

#!c:\perl\bin\perl

$Count = 0;
$pt = 2;
while ( $Count < @ARGV[0] )
{
if (isPrimary($pt))
{
print "$pt\n";
$Count++;
}
$pt++;
}

sub isPrimary
{
$flag = 1;
for ($i=2; $i<=$_[0]/2; $i++)
{
if ($_[0] % $i == 0)
{
$flag = 0;
}
}
return $flag;
}

Download CGI Perl PDF Read All 18 CGI Perl Questions
Previous QuestionNext Question
Why we use "use lib $path"?Write a script to display mirror image of a entered value and also check whether Palindrome?