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

Why do we use "use strict" in perl?

922


What exactly is grooving and shortening of the array?

966


How many types of primary data structures in Perl and what do they mean?

1345


Explain substr function in perl?

972


how to connect cisco switch uisng perl script

3801


How do you turn on the perl warnings?

876


Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?

1047


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

902


What happens when you return a reference to a private variable?

950


Write a program to concatenate the $firststring and $secondstring and result of these strings should be separated by a single space.

1015


What does -> symbol indicates in Perl?

928


How to read a file into a hash array?

1002


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

885


Explain grooving and shortening of arrays and splicing of arrays?

852


Comment on the scope of variables in perl.

893