Question: Write a function bool isPrime(int n) that returns true if the integer n is prime, and false if it isnt. With your code, include a

  1. Write a function bool isPrime(int n) that returns true if the integer n is prime, and false if it isnt. With your code, include a main function that prompts the user for appropriate input, sends it to the function, and prints out the results.
  2. Using your function from a, write a function int nearestPrime(int n) that returns the prime number that is closest to n, regardless of whether its larger or smaller. For example, nearestPrime(7) is 7, while nearestPrime(8) is 7, and nearestprime(25) is 23. If there are two equally close primes, you may break the tie however you like.

Need help with part 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!