Need to find larger prime number then has been inputed.how to do that: I *cin* 5 the reult it self should be 7...?

marius2010
0
Newbie Poster

## Recommended Answers

Jump to PostI'm a bit confused on what you want, do you want to output a list of prime numbers whose range is upto the input or check if the input is a prime number or something else entirely?

Jump to PostHere's something I found on Google:

`bool checkPrime(int num){ if(num<=1) return false; if(num==2) return true; if(num%2==0) return false; for(int i=3; i<=sqrt(num*1.0); i+=2) if(num%i==0) return false; return true; }`

Also, if you want to get the next prime number, you could do it like this:

## All 7 Replies

zeroliken
79
Nearly a Posting Virtuoso

marius2010
0
Newbie Poster

Lucaci Andrew
140
Za s|n

marius2010
0
Newbie Poster

marius2010
0
Newbie Poster

NathanOliver
429
Veteran Poster
Featured Poster

Lucaci Andrew
140
Za s|n

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.