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 |
What is the difference beween joblib and steplib statements
I am taking the bmc control m/enterprise manager 7.0 scheduling test and just wanted to see what kind of questions they would ask or if anyone has taken the test and how long it is for how many questions?
Can we write a method in JSP.If so how?
Hi guys... I have one doubt ..Exception is a runtime error then why we have checked exception... Thanks in advance
What is meant byStatic Variable ?
Hai, My name is nisha.I have NIC exam.If anybody Knows NIC previous paper pattern pls send me to nishanairp@gmail.com
Find out the list of authorization objects which contains activity as a field? Thanks in advance.
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,
When you?re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?
What is a PID? How is it useful when troubleshooting a system?
10.Define filters,binary to hexadecimal,hexadecimal to decimal?
I need source code for Enrollment System using Visual Basic 6.0/2008 database MS Access 2007 for my school thesis project...please help me..kindly send in my email jpinedamcp@gmail.com