Please anyone tell me coding to print prime numbers from 1 to
5000 in c#....

Answers were Sorted based on User's Feedback



Please anyone tell me coding to print prime numbers from 1 to 5000 in c#......

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

Please anyone tell me coding to print prime numbers from 1 to 5000 in c#......

Answer / guest

int i=0;
for(i=0;i<=5000;i++)
console.writeline(i);

Is This Answer Correct ?    1 Yes 8 No

Post New Answer

More Programming Languages AllOther Interview Questions

What is the difference beween joblib and steplib statements

0 Answers   Maples,


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?

0 Answers  


Can we write a method in JSP.If so how?

0 Answers   HCL,


Hi guys... I have one doubt ..Exception is a runtime error then why we have checked exception... Thanks in advance

2 Answers  


What is meant byStatic Variable ?

7 Answers   Mascot,






Hai, My name is nisha.I have NIC exam.If anybody Knows NIC previous paper pattern pls send me to nishanairp@gmail.com

0 Answers  


Find out the list of authorization objects which contains activity as a field? Thanks in advance.

0 Answers  


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?

2 Answers   BirlaSoft,


What is a PID? How is it useful when troubleshooting a system?

3 Answers  


10.Define filters,binary to hexadecimal,hexadecimal to decimal?

0 Answers  


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

0 Answers  


Categories