now i am working on an exercise that asks to write this without recursion....
can anyone guide me to what i can do to make this work? i dont want anyone to do it for me but help would be appreciated.
/*
#include <cmath>
using namespace std;
void getAllDivisors(int n);
int getLowestDivisors(int x);
int main()
{
int n = 0;
system("clear");
while (true) {
cout << "Enter a number (0 = exit) and press ENTER: ";
cin >> n;
if (n == 0)
break;
getAllDivisors(n);
cout << "\n\n";
}
cout << endl;
return 0;
}
// get divisors function
// this function prints all the divisors of n,
// by finding the lowes divisor, i , and then
// running funciton get lowestdivisors
void getAllDivisors (int n)
{
int x;
double sqrtOfN = sqrt(n);
for (int i = 2; i <= sqrtOfN; i++) {
if (n % i == 0) {
cout << i << ", ";
getLowestDivisors(n/i);
}
cout << n;
return;
}
}
int getLowestDivisors (int x)
{
double sqrtOfX = sqrt(x);
for (int i = 2; i <= sqrtOfX; i++) {
if (x % i == 0) {
cout << i << ", ";
}
return x;
}
}
this is doing my head in, i understand now why recursions are so useful...