> For the complete documentation index, see [llms.txt](https://computerscienceeducation.gitbook.io/co-lab-manual/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://computerscienceeducation.gitbook.io/co-lab-manual/assignments/extra-assignments/a3-a-fibonacci-calculator.md).

# A3-a: Fibonacci Calculator

250 points

{% hint style="info" %}
**CMake targets**: `a3a-iter` `a3a-rec`&#x20;

```bash
cmake --build .build --target a3a-iter a3a-rec
```

{% endhint %}

{% hint style="danger" %}
You can receive points for either A3-a or A3-b, but not both!
{% endhint %}

0, 1, 1, 2, 3, 5, 8, 13, ... The Fibonacci Sequence may very well be one of the simplest yet intriguing sequences of numbers out there. Not only can it be found in nature in various forms but it also has some peculiar mathematical properties (for those interested, [this page](https://www.mathsisfun.com/numbers/fibonacci-sequence.html) gives a nice overview).

***

This assignment consists of two different implementations for the same function. Implement a subroutine with the following signature:

```c
uint64_t my_fib(uint64_t i)
```

Use the `a3a-fib-iter.S` file to give an **iterative implementation** and the `a3a-fib-rec.S` file for a **recursive implementation**. Further, use the `a3a-fib-main.S` file to give a **simple `main` routine** that gets a number from the user, calls the subroutine, and then pretty-prints the returned result. The output (for both versions) should look like this:

```
Enter an index: <i>
F_<i> = <fib(i)>
```

where `<i>` is the given input and `<fib(i)>` is the number in the Fibonacci sequence at index `i`.

### Note for using the Framework

The two targets `a3a-iter` and `a3a-rec` are entirely separate executables, that use the same main subroutine defined in `a3a-fib-main.S`. The only difference between the two is the implementation of the `my_fib` subroutine.

{% hint style="warning" %}
When debugging, make sure to select the correct target for the executable you are currently working on. Namely, for `a3a-iter` select *Debug A3A Fibonacci Iterative* and for `a3a-rec` select *Debug A3a Fibonacci Recursive*.
{% endhint %}
