Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
- 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.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started