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 to read a file into a hash array?

1053


What are perl strings?

897


What are the various uses of perl?

1045


What is chomp() operator/function?

1072


What is lexical variable in perl?

946


You want to read command-line arguements with perl. How would you do that?

900


What is hash?

1082


In CPAN module, name an instance you use.

964


What exactly is grooving and shortening of the array?

1021


what are the steps involved in reading a cgi script on the server?

939


What is eval function in perl?

960


What does Perl do if you try to exploit the execve(2) race involving setuid scripts?

949


You want to empty an array. How would you do that?

915


Explain goto label?

934


Mention what is cpan?

1022