CGI Perl Question:
Download Questions PDF

Write a script to generate n prime no.s?

CGI Perl Interview Question
CGI Perl Interview Question

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 Interview Questions And Answers PDF

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?