```
//Hi all,can you explain how to call this function in main.
//i ask user to enter the number,like this is it correct in main,recursevely call function?
bool isPrime(int n, int d);
int main()
{
int number;
cout <<"Enter number >= 1";
cin >> number;
if(isPrime(number))
{
return
cout << "Yes";
else
return
cout << "No";
}
return 0;
}
bool isPrime(int n, int d)
{
if(n<2)
return 0;
if(d == 1)
return true;
else
{
if(n % d == 0)
return false;
else
return isPrime(n, d - 1);
}
}
```

## Recommended Answers

Jump to PostYou would need to call

`isPrime()`

with two numbers, one the number you are checking and the other a number smaller than that but larger than it's square root.I would reccomend changing the name of

`isPrime()`

to`primeTest()`

and having a second function called`isPrime()`

, …

## All 2 Replies

Reply to this topic
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.