Skip to content

Instantly share code, notes, and snippets.

Created October 5, 2020 06:18
What would you like to do?
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int fibonacci(int n);
int main() {
clock_t begin, end;
float z;
int a;
begin = clock();
a = fibonacci(30);
end = clock();
z = (end - begin)/CLOCKS_PER_SEC;
printf("Fibonacci number(30): (%d) in %d s = %d / %d s", a, z, (end - begin), CLOCKS_PER_SEC);
int fibonacci(int n) {
if (n > 2)
return fibonacci(n-2) + fibonacci(n-1);
if (n == 2 || n == 1)
return 1;
return 0;
Copy link

phabee commented Oct 5, 2020

Simple demonstration to calculate the n-th element of a fibonacci sequence in C using recursion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment