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?

Answers were Sorted based on User's Feedback



write a script to generate n prime no.s?..

Answer / 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

write a script to generate n prime no.s?..

Answer / dushant

import java.io.*;
import java.util.*;

class Prime
{
static BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
int cnt = 0,j;
Prime()
{
try
{
System.out.print("Enter A Number :");
int n = Integer.parseInt(br.readLine());


for(int i =1 ;i <= n ;i++)
{

for( j = 1 ; j <= i ;j++)
{
if(j==1) //as 1 is Common Factor For
All
{
cnt ++;
}
if(i % j == 0 && j !=i) //Condition j!=i because at
1st loop
//i=1 j=1 so i%j==0 and 1 is not prime no
{
cnt ++;
}
if(cnt == 3)
{
break;
}
if(cnt==2 && i == j )
{
System.out.println(i);
}
}
cnt=0;

}

}
catch(Exception e)
{
System.out.println(e);
}


}

public static void main(String args[])
{
new Prime();
}
}

Is This Answer Correct ?    7 Yes 3 No

Post New Answer

More CGI Perl Interview Questions

Why should I use the -w argument with my Perl programs?

0 Answers  


What are the logical operators used for small scale operations? Explain them briefly.

0 Answers  


What are stdin, stdout and stderr?

0 Answers  


In Perl, there are some arguments that are used frequently. What are that arguments and what do they mean?

0 Answers  


Why do you use Perl?

0 Answers  


How interpreter is used in perl?

0 Answers  


What purpose does each of the following serve: -w, strict, - T ?

2 Answers  


Show the use of sockets for the server and client side of a conversation?

0 Answers  


Explain perl. What are the advantages of programming in perl?

0 Answers  


How do I sort a hash by the hash key?

0 Answers  


Write a script to reverse a string without using perl's built in functions?

0 Answers  


What is the purpose of redo statement?

0 Answers  


Categories