# How can I generate series of prime number using functions on C++?

1. 45
yosiyasposted 6 years ago

How can I generate series of prime number using functions on C++?

here is my code so far:
#include
#include
bool isprime (int num);
int main()
{

int num=0;
int i=0;

printf("Enter numbers &gt; ");
scanf("%d", &amp;num);

while (i

2. 73
Rising Carenposted 6 years ago

To test if any number is prime, it's:

bool prime = true;
int i = 2;

while(prime &&  i less than number)
{
if(number % i == 0)
prime = false;

i++;
}

That's the most basic prime checker that can be created, though it's inefficient.
One way to make it more efficient is to make a list of all the primes found and have the number check off against the list first, then test the numbers between the last prime number and itself.

However, without knowing exactly what the program will do (and your question is cutoff so I can't tell), I cannot recommend something more specific.

3. 45
yosiyasposted 6 years ago

#include
#include
bool isprime ( int num );
int main()
{

int num=0;
int i=0;

printf("Enter numbers > ");
scanf("%d", &num);

while (i

4. 42
taheruddinposted 6 years ago

working