Question #2177

& Even numbers and primes.
<br>(a) Write a is_prime(n) function. <br>
It should accept a positive integer n>1 as input, and output True or False, depending on whether n is or is not a prime number. Do this with a loop that checks whether for any integer d, 1 < d < sqrt(n), d divides n.
I'd suggest a while loop -- think carefully about the conditional for the loop, and when you want to change
this conditional inside the loop. (Use a boolean for your condition).
<br><br>
(b) Write a prime_sum(n) function.<br>
It should accept an even number n>1 as input, and via a loop search for primes p & q with p + q = n.
Hint: start with p = 3. If (p) and (n-p) are prime you are done. If not, set p+=2 and try again.
<br><br>
(c) Main.
<br>i) Ask the user for an even number n. Continually ask them until they do give you a positive even number. <br>
ii) Search for the summands p & q, and either print them out (if they exist) or say they don't. <br>
iii) Ask the user if they wish to try with another even, and let them continue until they quit.

Expert's answer

Unfortunately, your question requires more work than to be done for free. You can submit it as an assignment to our control panel set the deadline and our programmers will assist you.

## Comments

## Leave a comment