Last active
August 29, 2015 14:20
-
-
Save rogerioagjr/97483f4174568e113b06 to your computer and use it in GitHub Desktop.
Fibonacci
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 <cstdio> // scanf e printf | |
int fib(int n){ // declaro a função fib que recebe um inteiro como parâmetro | |
if(n<=1) return n; // se ele for menor que 2, a função deve retornar ele mesmo | |
return fib(n-1)+fib(n-2); // se não, deve retornar a soma dos dois termos anteriores da sequência | |
} | |
int main(){ | |
int num; // declaro o inteiro num | |
scanf("%d", &num); // leio o valor de num | |
printf("%d\n", fib(num)); // imprimo uma única linha com o valor de fib(num) | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment