Created
February 16, 2016 02:38
-
-
Save batmantec/3ab093f33ee801a6fbdf to your computer and use it in GitHub Desktop.
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; | |
int fib (int x) | |
{ | |
int y; | |
if (x>=2) | |
{ | |
y=fib(x-1) + fib (x-2); | |
return y; | |
} | |
else | |
{ | |
if (x==1) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
} | |
int main () | |
{ | |
int x, ans; | |
cout << "This program calculates the Fibonacci number that you want."<<endl; | |
cout << "Give me a number: "; | |
cin >> x; | |
ans = fib (x); | |
cout << "The Fibonacci number is: "<<ans<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment