Skip to content

Instantly share code, notes, and snippets.

@batmantec
Created February 16, 2016 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmantec/3ab093f33ee801a6fbdf to your computer and use it in GitHub Desktop.
Save batmantec/3ab093f33ee801a6fbdf to your computer and use it in GitHub Desktop.
#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