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

5. Which of the following can you do with DB2 Express- C? Query databases with SQL Query databases with XML using XQuery and XPath Use SQL in Xquery and Xquery in SQL All of the above

0 Answers  


qtp 9.2 14 days demo version was expired.I uninstalled how to reinstall this again

0 Answers  


What are two of your strengths that you will bring to our QA/testing team?

0 Answers  


For a binary tree with n nodes, How many nodes are there which has got both a parent and a child?

0 Answers  


To sorting array of 10 elements which sorting is best a)selection b)bubble c)tree sort

2 Answers   HP, Hughes,


What's the difference b/w Table & Templete in Smartform?

0 Answers   Accenture,


how to avoid java script validation in client side validation?

2 Answers  


difference between mantis and other tools?

0 Answers  


Given a arbitrary pointer to an element in a singly linked list?what is the time complexity for its deletion .

1 Answers   Hughes,


what is delegate and delegation model give the real live example on delegate model

0 Answers   TCS,


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

1 Answers   nvidia,


Given: coordinates of rectangle-> left bottom and right top points. the rectangles create a hole.Find the maximum area of the hole. eg. 4 rectangles create a hole in between. find its area.

0 Answers   Manhattan,


Categories