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
9.Difference between even and odd signals?explain with the diagram?
Any real time example of O2C process from taking order till creating invoice.
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?
How to connect the .accdb database file of microsoft access to the Visual Basic 6.0 forms?
Write a program to swap the content of two variables without using a third variable.
what is woransient key word? how it is used in java
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.
how to add a new table with variables and thier values into a imported file uisng proc import?
Is there any standard procedure to test the application as a whole? Or How can I test complete application right from the requirement gathering?
what is adodb??y it is used for connection of V.B and access??what is ado?dao?
Tell me the jobs for the MCA Fresher in delhi, Noida..
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.
How does the type system works when there is interoperability between a COM and .Net, i mean what exactly happens there
What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
what are resources in case of Threads