フィボナッチ数列




ソース

  <script type="text/javascript">
    function showArgument(m) {
      document.form.textarea.value += ("argument = "+m+"\n");
    }

    function showResult(m, r) {
      document.form.textarea.value +=("result for argument: "+m+" = "+r+"\n");
    }

    function fib(m) {
      showArgument(m);
      var r; 
      if (m<2) {
        r=1;
      } else {
        r=fib(m-1)+fib(m-2);
      }  
      showResult(m, r);
      return r;
    }    
        
    function exec() { fib(5); }
  </script>
  <form name="form">
  <input type="button" onClick="exec()" value="click"><br>
  <textarea name="textarea" cols="32" rows="39"></textarea>
  </form>

Koji Kagawa