944,126 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 276
  • C++ RSS
Oct 22nd, 2009
-4

c++ code need answer

Expand Post »
write a function that determine whether a number is prime.
Reputation Points: 5
Solved Threads: 0
Newbie Poster
rechene is offline Offline
2 posts
since Oct 2009
Oct 22nd, 2009
0
Re: c++ code need answer
Do it yourself.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 22nd, 2009
0
Re: c++ code need answer
Why don't you try searching the forums? The whole point of keeping the code in previous threads is so people will be able to learn from them in the future. I've seen this question asked many times in the past few weeks. Or you can actually try doing it yourself (that would be the prefered method)
Reputation Points: 100
Solved Threads: 48
Posting Pro in Training
Grn Xtrm is offline Offline
495 posts
since Nov 2008
Oct 22nd, 2009
-2
Re: c++ code need answer
Hi,

simple solution would be this boolean method...

returns true if it is prime, false otherwise...

C++ Syntax (Toggle Plain Text)
  1. #include <cmath>
  2.  
  3. bool IsPrime(int num)
  4. {
  5. if(num == 0)
  6. return true;
  7.  
  8. num = abs(num);
  9.  
  10. for(int i = 2; i <= sqrt(num); i++)
  11. if(num % i == 0)
  12. return false;
  13.  
  14. return true;
  15. }


ps...google
Reputation Points: 13
Solved Threads: 1
Newbie Poster
Unix* is offline Offline
14 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: binary tree insert
Next Thread in C++ Forum Timeline: number to word problem... help..!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC