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 |
Diff between Proc transpose and Arrays with example?
1. How many jobs can we write in a single file? 2. How many maximum members can exist in a single partition data set(pds) in jcl?
preorder of A*(B+C)/D-G
Is class is a abstract datatype in java?
what will we require to build project with the help of oracle
< No Frames > tag is used for
i need informatica certification dumps(S-powercenter 8 mapping designer)......plz fwd it to my mail id:gaya1989@yahoo.com
what is the difference between a namespace and assembly ?
explain how to make a control visible and invisible during runtime
There are 3 jars containing two types of round marbles. One jar contains only red marbles, one jar contains only blue marbles and the third jar contains a mix of both red and blue marbles. Although the jars are labeled “red”, “blue” and “mixed” – all the jars are mislabeled. How many marbles would you have to pull out, and out of which jars, to find out how to fix the labels correctly?
Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.
How many ways we can fill a dataset in .Net