Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do I read command-line arguments with Perl?

1069


What is confess function in perl?

998


What happens in dereferencing?

1109


What happens to objects lost in "unreachable" memory, such as the object returned by Ob->new() in `{ my $ap; $ap = [ Ob->new(), $ap ]; }' ?

1040


Can we load binary extension dynamically?

999


How do I debug a perl program?

1031


How to know whether a key exists or not in perl?

1021


Write a program that explains the symbolic table clearly.

1008


What do you mean by context of a subroutine?

1028


what is the main function of fork() in cgi programming?

1216


What is cpan ? What are the modules coming under this?

974


What is the syntax used in Perl grep function?

1080


What is the difference between use and require in perl?

917


How many types of operators are used in the Perl?

1074


There are some duplicate entries in an array and you want to remove them. How would you do that?

956