-
Write a recursive function
void factors(int n) that
prints out the factorization of n.
- What's the base case?
- How could a recursive call to
factors with a smaller
n-value help solve the problem?
Use 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 a solution
- Make change
~$ ./change
Enter amount: 134
Change to give is: QQQQQNPPPP
~$ ./change
Enter amount: 32
Change to give is: QNPP
Solution.
- Any thoughts on how you could
modify to print out coins in increasing value?
- Printing in binary
~$ ./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 10000000000000000
Solution
- Fibonacci Numbers
- Computing Continued Fractions
- Writing Continued Fractions in HTML