jump to last post 1-4 of 4 discussions (4 posts)

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 > ");

scanf("%d", &num);

while (iTo 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.#include

#include

bool isprime ( int num );

int main()

{

int num=0;

int i=0;

printf("Enter numbers > ");

scanf("%d", &num);

while (i

Related Discussions

- 2
### How can I generate sieres of prime number using function in C++?

by yosiyas6 years ago

How can I generate sieres of prime number using function in C++?#include #include bool isprime (int num);int main(){int num=0;int i=0;printf("Enter numbers > ");scanf("%d", &num);while...

- 2
### How much could MR.T bench press in his prime and the present day now?

by David 4707 years ago

How much could MR.T bench press in his prime and the present day now?

- 3
### What number can be divided by 7, 9, & 11?

by Grace Marguerite Williams15 months ago

What number can be divided by 7, 9, & 11?

- 3
### Is there a pattern to the sequential distribution of prime numbers?

by stanwshura5 years ago

Is there a pattern to the sequential distribution of prime numbers?3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53...The space between is, in order : 2, 2, 4, 2, ...

Copyright © 2018 HubPages Inc. and respective owners.

Other product and company names shown may be trademarks of their respective owners.

HubPages^{®} is a registered Service Mark of HubPages, Inc.

HubPages and Hubbers (authors) may earn revenue on this page based on affiliate relationships and advertisements with partners including Amazon, Google, and others.

terms of use privacy policy (0.62 sec)

working