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

Hi friends :) This Company Aptitude Questions were much easy. i have attended the interview but was not selected in the HR round. they used to ask questions like puzzles, English, fill up the sentence. for example : they asked one question like suraj, kumar, santhosh, ranga and ashwin are professionals in different fields. suraj is a doctor. kumar is not a musician.ranga is working as engineer. ashwin is from goa. santhosh is from chennai. suraj and ranga are not from delhi. find out who is working in which field and where are they from? it was not the exact question. i answered that question with correct answer. just thorough with SQL queries. they are much interested in that. i cleared Technical round where they asked me to write a C code for checking, if the given word is palindrome or not. also they asked 2 puzzle question to solve in front of them. then the asked SQL query for referring two tables. then, they sent me for HR round. i got little nervous in that round. so, could not answer them properly. In Hr round, they may ask Technical Questions. i was asked only Technical Questions in HR round. they asked questions from SQL queries and my project. i could not answer for the questions perfectly. so, i was not selected. anyway, try to be thorough with these info and rock in your interview. Thanks :)

0 Answers   Hewitt,


Why we need new operator in java at the time of object declaration and why not in c++?

1 Answers   Zensar,


Write a Pseudo Code to find the angle between two hands of a clock for a given time.

6 Answers   Goldman Sachs, HCL,


What is autocall macro and how to create autocall macro? what is the use of it?

0 Answers   GE,


Hi Guys, This is Rama, right now I am working as a Software Test Engineer in Gurgoan and I have over all 3 years of testing expoeriance. Right now I am looking for a change. Can any body help me out to find a job in south india. Thanks in Advance

0 Answers  






Java is called as pure objerct oriented programming language, where as c++ is not completely object oriented.can any explain the detailed differenec between these two

4 Answers  


Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming

1 Answers  


It is possible to take number of controls added to form at run-time.ex-when user enter 6, 6 text boxes get added to form,next time number of controls get change as per user number enter. What is code for that?

0 Answers   Honeywell,


how many logical drive we can form to physical device in our computer?

1 Answers   nvidia,


what is the software to run the GSM gate opener program

0 Answers  


What is nocopy in plsql?

1 Answers   IBA Health,


what is an INI file?

0 Answers   EID Parry,


Categories