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
How to read a file into a hash array?
What are perl strings?
What are the various uses of perl?
What is chomp() operator/function?
What is lexical variable in perl?
You want to read command-line arguements with perl. How would you do that?
What is hash?
In CPAN module, name an instance you use.
What exactly is grooving and shortening of the array?
what are the steps involved in reading a cgi script on the server?
What is eval function in perl?
What does Perl do if you try to exploit the execve(2) race involving setuid scripts?
You want to empty an array. How would you do that?
Explain goto label?
Mention what is cpan?