1
1

More than 5 years have passed since last update.

漸化式

Last updated at Posted at 2017-06-14

数学2・Bの範囲ではじめて聞く単語、漸化式。
単なる再帰関数のことと考えてよい。

function a(n){
  if(n == 1){
    return 2;
  }
  return a(n-1) + 3;
}

function b(n){
  if(n == 1){
    return 2;
  }
  return 3 * b(n-1);
}

for(i=1; i<5; i++){
  console.log(a(i));
}

console.log('-----------------');

for(i=1; i<5; i++){
  console.log(b(i));
}
~ % node hoge.js
2
5
8
11
-----------------
2
6
18
54
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1