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 do I read command-line arguments with Perl?
What is confess function in perl?
What happens in dereferencing?
What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?
Can we load binary extension dynamically?
How do I debug a perl program?
How to know whether a key exists or not in perl?
Write a program that explains the symbolic table clearly.
What do you mean by context of a subroutine?
what is the main function of fork() in cgi programming?
What is cpan ? What are the modules coming under this?
What is the syntax used in Perl grep function?
What is the difference between use and require in perl?
How many types of operators are used in the Perl?
There are some duplicate entries in an array and you want to remove them. How would you do that?