c++ code need answer

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 2
Reputation: rechene has a little shameless behaviour in the past 
Solved Threads: 0
rechene rechene is offline Offline
Newbie Poster

c++ code need answer

 
-4
  #1
Oct 22nd, 2009
write a function that determine whether a number is prime.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,988
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Cenosillicaphobiac
 
0
  #2
Oct 22nd, 2009
Do it yourself.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 467
Reputation: Grn Xtrm will become famous soon enough Grn Xtrm will become famous soon enough 
Solved Threads: 39
Grn Xtrm's Avatar
Grn Xtrm Grn Xtrm is offline Offline
Posting Pro in Training
 
0
  #3
Oct 22nd, 2009
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)
Check out my new band URL on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
URL on facebook!
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 14
Reputation: Unix* is an unknown quantity at this point 
Solved Threads: 1
Unix*'s Avatar
Unix* Unix* is offline Offline
Newbie Poster
 
-2
  #4
Oct 22nd, 2009
Hi,

simple solution would be this boolean method...

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

  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
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 202 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC