Create exercise_06_07.c

Thanks for doing this repo.  I currently reading through the book and have found it helpful to check my answers with yours.  Found a bug in this code that results in getting a lot of numbers listed as prime that are not prime.  The problem is you have j++ after the 2nd while loop which results in that 2nd while loop never being used again.  Your first time through the 2nd while loop i = 2 and the loop stops when j=75 as 275 = 150.  So the while loop ends and you increment i up to 3.  But you also increment j so you get j = 76.   The next time through the while loop you then have 376 which is greater than 150 so the while loop will never again be used.  9 for instance is listed as a prime number, but if you just change j=i after you increment i then you get the desired result.  But again big thanks for doing this repo.  Best, Kevin

Ok thanks will have a look at your version asap
On 8 Jun 2017 18:44, "Kevin Clauson"<EMAIL_ADDRESS>wrote:

Thanks for doing this repo. I currently reading through the book and have
found it helpful to check my answers with yours. Found a bug in this code
that results in getting a lot of numbers listed as prime that are not
prime. The problem is you have j++ after the 2nd while loop which results
in that 2nd while loop never being used again. Your first time through the
2nd while loop i = 2 and the loop stops when j=75 as 275 = 150. So the
while loop ends and you increment i up to 3. But you also increment j so
you get j = 76. The next time through the while loop you then have 376
which is greater than 150 so the while loop will never again be used. 9 for
instance is listed as a prime number, but if you just change j=i after you
increment i then you get the desired result. But again big thanks for doing
this repo. Best, Kevin
You can view, comment on, or merge this pull request online at:
https://github.com/HenrikSamuelsson/Programming-in-C/pull/1
Commit Summary

Create exercise_06_07.c

File Changes

M Exercises/Chapter_06/Exercise_07/exercise_06_07.c
https://github.com/HenrikSamuelsson/Programming-in-C/pull/1/files#diff-0
(3)

Patch Links:

https://github.com/HenrikSamuelsson/Programming-in-C/pull/1.patch
https://github.com/HenrikSamuelsson/Programming-in-C/pull/1.diff

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/HenrikSamuelsson/Programming-in-C/pull/1, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AFGuRqhDdHHCOIhmidq5s_ex-fbozhyfks5sCCT-gaJpZM4N0VYR
.