Created
November 27, 2020 09:46
-
-
Save ahmet-cetinkaya/4052626e410b85916886a0162515432d to your computer and use it in GitHub Desktop.
C++ Fibonacci Recursive Functions
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<iostream> | |
using namespace std; | |
// @params a is first number. | |
// @params b is second number. | |
// @params c is the upper limit of numbers. | |
int fobi(int a, int b, int c) { | |
int next = a + b; | |
if (next > c) return 0; | |
cout << next << " "; | |
return fobi(next, a, c); | |
} | |
// @params c is number of outputs. | |
int fibo2(int c) { | |
if (c == 1 || c == 0) return c; | |
return (fibo2(c - 1) + fibo2(c - 2)); | |
} | |
main() { | |
fobi(0, 1, 100); | |
for (int i = 1; i < 12; i++) cout << " " << fibo2(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment