Skip to content
Permalink
bc4cf004c6
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
19 lines (14 sloc) 398 Bytes
#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
uint64_t tailfibonacci(uint64_t n, uint64_t prev, uint64_t cur, uint64_t sum)
{
if (n == 0) return sum;
return tailfibonacci(n-1, cur, sum, sum+cur);
}
int main(int argc, char** argv)
{
uint64_t n = strtoull(argv[1], NULL, 0);
printf("Fibonacci(%" PRIu64 ") = %" PRIu64 "\n", n, tailfibonacci(n, 1, 1, 0));
return EXIT_SUCCESS;
}