Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Diff between Proc transpose and Arrays with example?

2 Answers   Accenture,


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?

0 Answers   Steria,


preorder of A*(B+C)/D-G

6 Answers   BFL,


Is class is a abstract datatype in java?

0 Answers  


what will we require to build project with the help of oracle

0 Answers  


< No Frames > tag is used for

0 Answers  


i need informatica certification dumps(S-powercenter 8 mapping designer)......plz fwd it to my mail id:gaya1989@yahoo.com

1 Answers  


what is the difference between a namespace and assembly ?

4 Answers   Innominds, Polaris,


explain how to make a control visible and invisible during runtime

3 Answers  


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?

1 Answers   Syntel,


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.

0 Answers   Amazon,


How many ways we can fill a dataset in .Net

1 Answers   iGate,


Categories