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 Postwell you need to use a loop and go from the next odd number greater than what you entered untill you find a number that is prime.
bool prime = false; while(!prime) { // check if number is prime // if number is prime set prime to …
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, networking, learning, and sharing knowledge.