A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 4 years ago
Problem Set 1, Problem 1. Counting prime numbers question:
My program is finding the prime numbers properly, but I can't figure out how to make it count just the prime numbers.
anonymous
 4 years ago
Problem Set 1, Problem 1. Counting prime numbers question: My program is finding the prime numbers properly, but I can't figure out how to make it count just the prime numbers.

This Question is Closed

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Here's this: http://pastebin.com/duQFNZ6D

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0It is much simpler then that. start out assuming the number is prime. Next all you have to do is check it the number is divisible by any number up to it's square root. if not it's prime so just break. You can check this with just running a loop to test number % index == 0 and if that test is true then the number is not prime then return false.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0just make sure to start the loop with i = 2 or you will get stuck in an infinite loop.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0You get stuck here is my code. (please try it on your own first) http://pastebin.com/ZZpeULiY

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0The frustrating problem with jimtuv and some other helpful responses to this question  problem 1 of set 2, is that they use concepts not taught yet in lectures 1 thru 3. Here is my code that was worked out with much time and frustration, but is simple and works with the bare bones concepts of a beginner. The trick is keeping the indentations correct. #generate n (odd numbers 3 to ?) n=3 count = 1 #go to 999 since we skipped 2 while(count<1000): #test n for prime i=2 while(i<n): if n%i==0: i=n if n%i!=0: i=i+1 if i==n: count=count+1 n=n+2 print n2 ##
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.