Created
December 16, 2013 11:54
-
-
Save darkturo/7985925 to your computer and use it in GitHub Desktop.
Fibonacci in c++ for 50 elements.
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 <sstream> | |
#include <string> | |
#include <iostream> | |
std::string __fibonacci(int a, int b, int iterations) | |
{ | |
std::stringstream sequence(""); | |
if (iterations > 0) { | |
sequence << a << " " << __fibonacci(b, b + a, iterations - 1); | |
} | |
return sequence.str(); | |
} | |
std::string fibonacci(int n) | |
{ | |
return __fibonacci(1, 1, n); | |
} | |
int main() | |
{ | |
int numero = 50; | |
std::cout << "Fibonacci con " << numero << "elementos: " << fibonacci(numero) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment