WebAssembly Fibonacci Demo
A small demo that calls a Fibonacci function compiled to WebAssembly from C. Enter an integer and press Calculate.
References
Dynamic-programming Fibonacci (C)
Below is another version of the Fibonacci series using dynamic programming. It will be implemented in WebAssembly later.
#include <stdio.h>
long fib(int i);
int main()
{
long oput = fib(30);
printf("%ld", oput);
return 0;
}
long output[1000] = {0};
long fib(int i){
long result;
result = output[i];
if (i == 0) {
result = 0;
} else if (i == 1) {
result = 1;
} else {
if (output[i] != 0) {
return output[i]; // use the previously calculated fib
} else {
result = (fib(i - 2) + fib(i - 1));
}
}
output[i] = result;
return result;
}