DRAGON SWALLOWED HIM... END OF STORY
Carey Brown wrote:A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
Your program treats '1' as prime. (among other problems)
DRAGON SWALLOWED HIM... END OF STORY
All things are lawful, but not all things are profitable.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Knute Snortum wrote:It has to do with line 13, the j loop, and when it terminates. But there's other things too, such as how the isPrime variable is set.
DRAGON SWALLOWED HIM... END OF STORY
Campbell Ritchie wrote:Welcome to the Ranch
When you sort out the other problems, I challenge you to rewrite your loops so as to avoid break. Also, maybe those of us more experienced could find a solution with a
Why did you choose that type for isPrime?
DRAGON SWALLOWED HIM... END OF STORY
Mishra Saurabh wrote:
Campbell Ritchie wrote:Welcome to the Ranch
When you sort out the other problems, I challenge you to rewrite your loops so as to avoid break. Also, maybe those of us more experienced could find a solution with a
Why did you choose that type for isPrime?
Yes I did, I made it without the break and I also chose not to include isPrime as a boolean, instead I chose an integer to work as an integer that I declared inside the first loop. It works fine now..
DRAGON SWALLOWED HIM... END OF STORY
fred rosenberger wrote:what purpose does count serve? you set it to 1 initially. But if the range is 8-9, there are no primes between, but you've already counted one.
Is the range inclusive or exclusive?
It should be pretty obvious why 2 isn't considered prime. You default to "false". if your lower limit is 2, then your inner loop is from j=2 to (2/2) or 1, so the loop never executes, and so isPrime is never set to true.
DRAGON SWALLOWED HIM... END OF STORY
DRAGON SWALLOWED HIM... END OF STORY
Consider Paul's rocket mass heater. |