Help!! I have no idea on how to write the recursion code to find prime factors of numbers. The program is supposed to call the void function primeFactor() and it should be only one parameter of type long. (not sure if I did that right).
Here's what the code should look like:
Examples:
Please enter a whole number greater than 1: 5
5 = (5) :Prime!
continue? (Y/N) Y
Please enter a whole number greater than 1: 28
28 = (2)(2)(7)
continue? (Y/N)
int main(void)
{
long primeFactor , prime;
long whole = 0;
char again = 'N';
bool a =true;
do
{
system("cls");
cout << "Please enter a Whole number greater than 1: ";
cin >> whole;
cin.get();
if(whole < 0) // cannot be negative number not defined
{
cerr << "Whole number cannot < 1!" << endl;
cerr << "Press the \"Enter\" key to continue";
cin.get();
}
Accepting that 2 is the only even prime, your for loop should be checking odd numbers as divisors of the input integer. But this is an iterative method.
For recursion use:
n!= 1 (if n=0) ......basis formula
n!= n . (n-1)! (if n > 0)..........recurrance formula