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
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.
what is delegate and delegation model give the real live example on delegate model
Given an array of size n, containing every element from 1 to n+1, except one. Find the missing element.
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??/
Plz sent me in .net 2.0 interview Question & answers?
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
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 the entry point function of a DLL?
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
Write a program to find factorial of a number using functions
Suppose server object is not loaded into the memory, and the client request for it , what will happen?
how can we maintain the previous version scripts to new version.
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
what is the meaning of without standing arrears?
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