### Prime Numbers

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243`` ``````#include using namespace std; int main() { //input output cout << "please input a number" <> inputtedNumber; cout << "The prime number between 3 and that number are:" << endl; int candidate = inputtedNumber; // temporary //eventually going to put outer loop // all numbers between 3 and the inputted numbers //this code here tests if canidates is prime //loop between the 3 and inputted // to see if they divide evenly. //for looop here betweeen 3 and a canidate int i; bool prime = true; for (i = 2; i < candidate; i++) { cout << candidate << "%" << i << "is"; cout << candidate %i << endl; cout << "PRIME IS " << ((prime)?"true" : "false") <

I don't understand what I am doing wrong...its supposed to tell whether the inputted number is prime or not
Here's my algorithm

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include #include #include using namespace std; int main(int nNumberofArgs,char* pszArgs[]) { int number; int counter = 0; cout << "Enter an Integer: "; cin >> number; int divisible[number]; for(int a = 1;a <= number;a++) { if(number % a == 0) { counter++; divisible[counter - 1] = a; } } if(counter == 2) { cout << number << " is prime!" << endl; } else { cout << number << " is not prime!" << endl; cout << number << " is divisible by: "; for(int i = 0;i < number;i++) { cout << divisible[i]; if(divisible[i + 1] != NULL) { cout << ", "; } else { break; } } cout << endl; } system("PAUSE"); return(0); }``````
Topic archived. No new replies allowed.