Last active
August 27, 2020 18:00
-
-
Save ErickGiffoni/c3be3c048540ef860f6738460152642c to your computer and use it in GitHub Desktop.
How to calculate Fibonacci's sequence using recursion ? I'll show you! This program shows a specified number of Fibonacci's sequence, based on the input from the user, which is that number's position.
This file contains hidden or 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> | |
/* This program shows a specified number of Fibonacci's sequence, | |
out of the input from the user, which is that number's position. | |
*/ | |
// Code made by Erick Giffoni | |
// contact : [email protected] | |
// github : https://github.com/ErickGiffoni | |
// linkedin : https://www.linkedin.com/in/erick-giffoni-022565167/ | |
// Copyright © 2018 Erick Giffoni . All rights reserved. | |
int fib(int number); | |
int main(){ | |
int number; | |
printf("Type down a number: "); | |
fflush(stdin); | |
scanf("%d", &number); | |
printf("The %d number of Fibonacci sequence is : %d\nWooowww\n", number+1, fib(number)); | |
return 0; | |
} | |
int fib(int number){ | |
int result = 0; | |
result = number == 0 ? 0 : (number == 1 ? 1 : fib(number-1)+fib(number-2)); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For largest numbers this algorithm fails. I'll post another gist with a much better algorithm.
Here is the link : https://gist.github.com/ErickGiffoni/d037c3225a7c1d25ea463a1f62873eb9