Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Literature

Name: Novice 2011-01-23 17:10

I'm in no way even a decent programmer. I'd like to become better, and have already settled on C++ as the language to begin with. I've learned quite a bit from reading documentation and online tutorials, etc, but I think it's time to read an actual book on C++.

What book(s) should I get and why?

Name: Anonymous 2011-01-24 17:54

>>26
Exercise 1.11.  A function f is defined by the rule that f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n>= 3. Write a procedure that computes f by means of a recursive process. Write a procedure that computes f by means of an iterative process.

"use strict"
function f(n) {
    if (n < 3) {
      return n;
    }
    return f(n-1) + 2 * f(n-2) + 3 * f(n-3);
}


"use strict"
function f(n) {
   var arr = [0, 1, 2];
   if (n < 3) {
       return arr[n];
   }

   for (var i=3; i <= n; i++) {
       arr[i] = arr[i-1] + 2*arr[i-2] + 3*arr[i-3];
   }
   return arr[n];
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List