Hey guys so I am trying to modify this without using function pointers. And so that I do not have to use a file to show the results. I'm not sure where to start modifications.
change the file pointer to ofstream. I know you know that ... your other program has one in it.
get rid of the c headers.
fib is like factorial... you can't get very far with it in 64 bits, so a lookup table is really the way to go if you just want the answers. Theres a way to get it from an equation as well, but you have roundoff to deal with. I think you can cram right at 100 values in a 64 bit int so its a relatively tiny table. Whole thing becomes like 4 lines of code.
#include <iostream>
usingnamespace std;
int fib(int n);
int main()
{
// Testing the first 4 values of the Fibonacci sequence
for (int i = 0; i < 4; i++){
cout << "fib(" << i << ") = " << fib(i) << endl;
}
}
int fib(int n)
{
if (n == 0)
return 0;
if (n == 1)
return 1;
return fib(n-1) + fib(n-2);
}