Please anyone tell me coding to print prime numbers from 1 to
5000 in c#....
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / guest
int i=0;
for(i=0;i<=5000;i++)
console.writeline(i);
| Is This Answer Correct ? | 1 Yes | 8 No |
Suppose server object is not loaded into the memory, and the client request for it , what will happen?
What are the Short cut Keys of Tally ERP?
How should a programmer decide whether to use a macro or a subroutine to accomplish a given logical function
1 Answers R V College of Engineering, University of Jordan,
what is the certificates in biztalk?
i am getting the error while compiling my cics program with including db2 dclgen member it is showing that ur dclgen member not including and all the host variables are undeclared
in a company 30% are supervisors and 40% employees are male if 60% of supervisors are male. what is the probability that a randomly choosen employee is a male or female?need steps to solve this?
What are the advantages of Server Controls over HTML/ASP Controls.
Which tag is used to create the frame
differenc between visual studio 2005,2008 & 2010?
How to change the color of a cell or a row in a datagrid on mouse hover using javascript/.net
what is programmable BIST in today ic design
Please describe an example where you used object orientation in one of your programs.