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

Define distributed queries. can you explain me as soon as possible

0 Answers   HCL,


How does the TCP handle the issue of multiplexing?

0 Answers  


What is the difference between: x=a+b+c+d; and x=SUM(a,b,c,d);?sas

5 Answers  


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,


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,


DIFFERENCE BETWEEN BINDING LANG AND BIND DIR WHEN USING IN SERVICE PGM

0 Answers   CTS,


what is fisrt female program

1 Answers  


plz send me NIC Scientific Officer /Engineer-SB(Programmer) previous question paper or syllabus

2 Answers   NIC,


Question:Why is mapping required? Computer 'Paging' & 'Segmentation'. Question:Give the disadvantages of Havander's Strategies. Question: What do you mean by Belady's Anomaly. - Describe with example. Question: Discuss the various function of OS. Question: Give a brief discussion on schedulers & Dispatchers with respect to process management.

0 Answers  


what is technical system, business system, logical system in sap pi7.0

0 Answers   IBM,


What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?

2 Answers  


is it possible to desable particular parameter of the normal orcle report based on some condition ?????? if yes,wht is the function for desabling a parameter...

0 Answers  


Categories