Question: Add a function int nextPrime(int n); that returns the smallest prime greater than n. For example: nextPrime(14) == 17 nextPrime(17) == 19 Change the main

Add a function int nextPrime(int n); that returns the smallest prime greater than n. For example: nextPrime(14) == 17 nextPrime(17) == 19 Change the main function to test the new code. Here is my code: #include using namespace std; bool isPrime (int n); int nextprime (int n); int main() { int n; int f; bool result; int nextprime (n); cin >> n; cout << "Please enter number: " << nextPrime; return 0; } bool isPrime (int n) //second function to check true or false { for (int f = 2; f <= n - 1; f++) if (n % f == 0) return false; if (n <= 1) return false; else return true; } int nextPrime(int n) // last function as asked in the lab { while(1) { if(isPrime(n)) //finds whether next number is prime or not { return n; } n++; } } How can I make it work?

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!