Finding the sum of the first n primes and to use a while function
More Answers (2)
- You are testing if i is not a prime number, when you actually want to test whether it is a prime number, according to the statements that are executed in this case. Therefore, change ~isprime(i) to isprime(i).
- The while loop should continue until n prime numbers have been found. Yet your loop execution condition is prime_count <= n, which means that even if prime_count is equal to n the loop would continue to run until prime_count is n+1! Change prime_count <= n to prime_count < n and you are good to go.