|
To see how recursion works, let's consider the resursive function computing a
factorial number.
In particular:
|
~$ ./change Enter amount: 134 Change to give is: QQQQQNPPPP ~$ ./change Enter amount: 32 Change to give is: QNPPSolution.
void factors(int n) that
prints out the factorization of n.
factors with a smaller
n-value help solve the problem?
firstfactor(int) that you guys defined for me in a previous
homework (see below).
// Returns the smallest factor of n
int firstfactor(int n)
{
int i = 2;
while(n % i != 0)
i++;
return i;
}
Take a look at my solution
~$ ./binary Enter non-negative integer: 127 In binary that's 1111111 ~$ ./binary Enter non-negative integer: 11 In binary that's 1011 ~$ ./binary Enter non-negative integer: 65536 In binary that's 10000000000000000Solution