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...

Please anyone tell me coding to print prime numbers from 1 to
5000 in c#....

Answer Posted / slau

In PHP, translate C# yourself
//array for prime numbers
$primes=array(2); //speed trick - we know that 2 is prime
for ($i=3;$i<=5000;$i+=2) { //speed - check only odd numbers
//max. possible divisor for number
$maxdiv = sqrt($i);
for ($j=0; $j<count($primes); $j++) {
// if modulus = 0, number has divisor
if (0 == $i % $primes[$j]) {
break;
}
//if all possible prime divisors checked, add new prime
if ($primes[$j] > $maxdiv) {
$primes[] = $i;
echo "$i\n";
break;
}
}
}


not very brilliant, 10 mins for coding, but runs pretty fast

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When we have two versions of the dot net installed how does the compiler know which version of DLL it has to select to an application.

1858


what is delegate and delegation model give the real live example on delegate model

3225


Given an array of size n, containing every element from 1 to n+1, except one. Find the missing element.

1029


we create a pf with 3 fields.2 is defined as keyfields.we lock it with alcobj command.how we find out whether the file is locked or not?is it dspfd??/

1979


Plz sent me in .net 2.0 interview Question & answers?

2079


THERE ARE 4 SOURCE FILES WHICH CONTAINS SAME METADATA CREATE A TARGET THAT SHOULD DISPLAY THE FILE NAME ALONG WITH THE RECORD PLEASE SEND THE ANSWERFOR THIS QUESTION WITH MAPPING

2067


Is there any standard procedure to test the application as a whole? Or How can I test complete application right from the requirement gathering?

1874


What is the entry point function of a DLL?

993


If i have a dataset queried from Sql and I would like to insert the dataset into a specific node in an xml document how do I do this

2069


Write a program to find factorial of a number using functions

1640


Suppose server object is not loaded into the memory, and the client request for it , what will happen?

2612


how can we maintain the previous version scripts to new version.

1880


Hi can you please send me recent(present) interview questions and technical qyestions with answers for "BUSSIESS OBJECTS" and "DATA WAREHOUSE".pls its urgent for me my mail id is sekhar.cs82@gmail.com,manjuforgis@gmail.com. thanks in advance

2042


what is the meaning of without standing arrears?

10382


I have try to write a record in a TDQ from a fle.... what are the steps to do... can anybody plz come with a solution

2614