anonymous
  • anonymous
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.
MIT 6.00 Intro Computer Science (OCW)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions.

anonymous
  • anonymous
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.
MIT 6.00 Intro Computer Science (OCW)
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
Here's this: http://pastebin.com/duQFNZ6D
anonymous
  • anonymous
It 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
  • anonymous
Awesome, thanks!

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
just make sure to start the loop with i = 2 or you will get stuck in an infinite loop.
anonymous
  • anonymous
Right, got it.
anonymous
  • anonymous
You get stuck here is my code. (please try it on your own first) http://pastebin.com/ZZpeULiY
anonymous
  • anonymous
The 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

Looking for something else?

Not the answer you are looking for? Search for more explanations.