write a script to generate n prime no.s?
Answer Posted / venkat
#!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;
}
| Is This Answer Correct ? | 16 Yes | 4 No |
Post New Answer View All Answers
You want to open and read data files with perl. How would you do that?
Comment on array slicing and range operator
Explain different types of perl operators.
You want to download the contents of a url with perl. How would you do that?
Explain about typeglobs?
Which functions in perl allows you to include a module file.
What is hash?
What are scalars?
What does the’$_’ symbol mean?
Is perl compiler or interpreter?
What are the various perl data types based on the context?
What does the qx{ } operator do?
Explain lists in perl?
How to remove a directory in perl?
How do I read command-line arguments with Perl?