CGI Perl Question:
Download Job Interview Questions and Answers PDF
Write a script to generate n prime no.s?
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;
}
$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 Question | Next Question |
Why we use "use lib $path"? | Write a script to display mirror image of a entered value and also check whether Palindrome? |