I would probably get kicked out of school for this, but here is what I came up with.
Code:
#include <iostream>
using namespace std;
long fibonA(long numO, long numT, long findN, int plOne, int plTwo, int plThree) {
long sumInt;
sumInt = numO + numT;
if (plOne == findN) {
return numO;
}
if (plTwo == findN) {
return numT;
}
if (plThree == findN) {
return (numO + numT);
}
plOne += 3;
plTwo += 3;
plThree += 3;
return fibonA((sumInt + numT), ((sumInt + numT) + sumInt), findN, plOne, plTwo, plThree);
}
int main() {
long findNum, numOne = 0, numTwo = 1;
cout << "Which number do you want to find : ";
cin >> findNum;
cout << endl << "The number is : " << fibonA(numOne, numTwo, findNum, 1, 2, 3) << endl;
return 0;
}
EDIT: For clarity I should add that I count 0 as 1. (sequence A000045 in OEIS) off the Wikipedia page.
Also seems from the algorithm that wikipedia gives you that they want to start at 1,2,3,5,8 ... if that's the case then I just plugged in the algorithm on the site, and it works.
Not sure why you posted though as it took me about a minute to bring a website up with full code ( I was just curious after my laughable code above ). hehe.
Code:
#include <iostream>
using namespace std;
long fiboN(long varA)
{
if ((varA == 0) || (varA == 1))
return 1;
else
return fiboN(varA - 1) + fiboN(varA - 2);
}
int main()
{
long checkN;
cout << "Enter fibonacci number to check : ";
cin >> checkN;
cout << endl << fiboN(checkN) << endl;
return 0;
}