I’m trying to check whether the number is a prime(by dividing it by all numbers below n). Here’s my attempt :
bool isPrime(int n, int d){
if (d == 1)
return true;
else{
if (n % d == 0){
return false;
}
else
return (n,d-1);
}
}
n – the number to check whether it is prime.
d – number below n, when calling the function n-1.
Please help me figure out what am I doing wrong.
You aren’t recursively calling your function.
return (n,d-1);should bereturn isPrime(n,d-1);