---
# System prepended metadata

title: CH1

---

# CH1 
---
## Fibonacci Number費伯那西數列
```c++
#include <iostream>
using namespace std;
int fib(int a) {
    if (a == 0) 
      return 0;
    if (a == 1)
      return 1;
    else
      return fib(a-1)+fib(a-2);
    return 0;
}

int main() {
  cout << fib(7);
  return 0;
}

```
---
## Ackerman's Function
![](https://i.imgur.com/HGr7Aaf.png)

```c++
int Ackermann(int m, int n)
{
    if (m == 0)
        return n + 1;
    else if (m > 0 && n == 0)
        return Ackermann(m - 1, 1);
    else
        return Ackermann(m - 1, Ackermann(m, n - 1));
}

int main() {
  cout << Ackermann(4,1);
  return 0;
}

```
---
## 河內塔問題
```C++
#include <iostream>
using namespace std;
int step = 0;
int Hanoi(int n, char a, char b, char c) {
    if (n == 1) {
      cout << a << "to" << c << '\n';
      step++;
      }
    else {
      Hanoi (n-1,a,c,b);
      Hanoi (1,a,b,c);
      Hanoi (n-1,b,a,c);
    }
    return 0;
  }


int main() {
  int n;
  cin>> n;
  Hanoi(n,'A','B','C');
  return step;
}

```