Skip to content

Instantly share code, notes, and snippets.

@ErickGiffoni
Last active August 27, 2020 18:00
Show Gist options
  • Save ErickGiffoni/c3be3c048540ef860f6738460152642c to your computer and use it in GitHub Desktop.
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.
#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;
}
@ErickGiffoni
Copy link
Author

ErickGiffoni commented Jul 18, 2020

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

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