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

9.Difference between even and odd signals?explain with the diagram?

3447


Any real time example of O2C process from taking order till creating invoice.

2438


You are given some denominations of coins in an array (int denom[])and infinite supply of all of them. Given an amount (int amount), find the minimum number of coins required to get the exact amount. What is the method called?

1128


How to connect the .accdb database file of microsoft access to the Visual Basic 6.0 forms?

4353


Write a program to swap the content of two variables without using a third variable.

1123


what is woransient key word? how it is used in java

2445


1. Consider the following code in our example assembly language: ; an example bit of assembly code ROOT: W FATHER FATHER: W SON1 W SON2 SON1: W NIL W NIL ; ---------------------- SON2: W GRANDSON W NIL GRANDSON: W NIL W NIL NIL = 0 Assemble this code carefully following the two pass model, and show the symbol table at the point marked by the dashed line during each pass.

2359


how to add a new table with variables and thier values into a imported file uisng proc import?

1956


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

1992


what is adodb??y it is used for connection of V.B and access??what is ado?dao?

2255


Tell me the jobs for the MCA Fresher in delhi, Noida..

2449


I want sample papers for NIC Examination. Plz send them to my mail Id das.neelam@gmail.com . Plz send it today, tomorrow i've the exam.

2079


How does the type system works when there is interoperability between a COM and .Net, i mean what exactly happens there

2181


What ports must be open for DCOM over a firewall? What is the purpose of Port 135?

7996


what are resources in case of Threads

2354