Practice Problems

  1. Write a recursive function void factors(int n) that prints out the factorization of n. 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
  2. Make change
    ~$ ./change
    Enter amount: 134
    Change to give is: QQQQQNPPPP
    
    ~$ ./change
    Enter amount: 32
    Change to give is: QNPP
    
    Solution.
  3. Any thoughts on how you could modify to print out coins in increasing value?
  4. 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
  5. Fibonacci Numbers
  6. Computing Continued Fractions
  7. Writing Continued Fractions in HTML