Return a the number in the nth position of the Fibonacci sequence.
Example:
// Returns 34
get_fibonacci_n(9);
#define PI 3.14159265358979323846
#include <stddef.h>
#include <math.h>
size_t get_fibonacci_n(double n) {
if (n < 0) return -1;
double PHI = (1 + sqrt(5)) / 2;
double a = pow(PHI, n) - pow(-PHI, -n);
return (size_t)floor(a / sqrt(5));
}
#include <criterion/criterion.h>
// replace with the actual method being tested
size_t get_fibonacci_n(double);
Test(fibonacci_n, example_solution) {
cr_assert(get_fibonacci_n(9) == 34, "Expected 9th Fibonacci to be 34.");
}
Test(fibonacci_n, bigger_n) {
cr_assert(get_fibonacci_n(69) == 117669030460994, "Expected 69th Fibonnaci to be 117,669,030,460,994");
}