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)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
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.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Here's this: http://pastebin.com/duQFNZ6D
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.
Not the answer you are looking for? Search for more explanations.
just make sure to start the loop with i = 2 or you will get stuck in an infinite loop.
Right, got it.
You get stuck here is my code. (please try it on your own first)
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 ?)
count = 1 #go to 999 since we skipped 2
#test n for prime