| | |
Finding Prime numbers without using Boolean
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
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.
c Syntax (Toggle Plain Text)
#include <iostream> using namespace std; void prime_num(int); int main() { cout << " Enter a number and I will generate the prime numbers up to that number: "; int num = 0; cin >> num; prime_num(num); } void prime_num( int num) { bool isPrime=true; for ( int i = 0; i <= num; i++) { for ( int j = 2; j <= num; j++) { if ( i!=j && i % j == 0 ) { isPrime=false; break; } } if (isPrime) { cout <<"Prime:"<< i << endl; } isPrime=true; } }
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...
![]() |
Similar Threads
- C++ Finding Prime Numbers (C++)
- Prime Numbers - Help its for college (Visual Basic 4 / 5 / 6)
- prime numbers homework trouble (C++)
- help with array that determines prime numbers (C)
- prime numbers (C++)
- prime numbers (C++)
Other Threads in the C++ Forum
- Previous Thread: array, pointers, and strings in C++ please help me asap please.......
- Next Thread: compiling gcc/c++
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






