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
Why do we use "use strict" in perl?
What exactly is grooving and shortening of the array?
How many types of primary data structures in Perl and what do they mean?
Explain substr function in perl?
how to connect cisco switch uisng perl script
How do you turn on the perl warnings?
Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?
What does Perl do if you try to exploit the execve(2) race involving setuid scripts?
What happens when you return a reference to a private variable?
Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.
What does -> symbol indicates in Perl?
How to read a file into a hash array?
what are the steps involved in reading a cgi script on the server?
Explain grooving and shortening of arrays and splicing of arrays?
Comment on the scope of variables in perl.