Finding Prime numbers without using Boolean

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2007
Posts: 2
Reputation: jonnymac5987 is an unknown quantity at this point 
Solved Threads: 0
jonnymac5987 jonnymac5987 is offline Offline
Newbie Poster

Finding Prime numbers without using Boolean

 
0
  #1
Apr 26th, 2007
Here is a program which finds prime numbers, but because the compiler i need to use for my class does not use a boolean variable i am having trouble figuring this out. Please help me find how to find prime numbers without using a boolean variable.
  1. #include <iostream>
  2. using namespace std;
  3. void prime_num(int);
  4. int main()
  5. {
  6. cout << " Enter a number and I will generate the prime numbers up to that number: ";
  7. int num = 0;
  8. cin >> num;
  9. prime_num(num);
  10. }
  11.  
  12. void prime_num( int num)
  13. {
  14. bool isPrime=true;
  15. for ( int i = 0; i <= num; i++)
  16. {
  17. for ( int j = 2; j <= num; j++)
  18. {
  19. if ( i!=j && i % j == 0 )
  20. {
  21. isPrime=false;
  22. break;
  23. }
  24. }
  25. if (isPrime)
  26. {
  27. cout <<"Prime:"<< i << endl;
  28. }
  29. isPrime=true;
  30. }
  31. }
Last edited by WaltP; Apr 27th, 2007 at 1:36 am. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Finding Prime numbers without using Boolean

 
0
  #2
Apr 26th, 2007
Why not just use an int? Let 0 be false and anything else be true, like in C.

Also, please learn to use [code] and [/code] tags when you post, so we can read your code.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC