Permalink
Cannot retrieve contributors at this time
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?
fibonacci/tailfibonacci.c
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
19 lines (14 sloc)
398 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |