Question: need help with the following. I need to implement a recursive function to determine if a number is prime. Here is my code so far

need help with the following. I need to implement a recursive function to determine if a number is prime. Here is my code so far

need help with the following. I need to implement a recursive function

#include using namespace std; // Returns false if value is not prime, true if value is prime bool IsPrime(int testval, int divval) { // Base case 1: 0 and 1 are not prime, testVal is not prime // Base case 2: testVal only divisible by 1, testVal is prime // Recursive Case // Check if testVal can be evenly divided by divval // Hint: use the % operator // If not, recursive call to isprime with testVal and (divval 1) return 0; } int main(){ int primeCheckVal; // Value checked for prime // Check primes for values 1 to 10 for (primeCheckVal = 1; primeCheckVal

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!