The original question is: Define a function that produces the n'th Fibonacci number, according to the defeintion: fib(0)=1;fib(1)=1;fib(n)=fib(n-1)+fib(n-2)
I was trying to solve this with if & else structure in C programming . I did it successfully and tested it with some small inputs. When the input number is '45', everything seems alright. However when input '46', the result became negative which indicates something must have gone wrong. Really hope that someone can tell me why's that, and what was I doing wrong?
Source Code:
include
int fib(int i)
{
if (i == 0)
return 1;
else if (i == 1)
{
int result_1 = fib(i - 1);
return result_1;
}
else
{
int result_2= fib(i-1) + fib(i-2);
return result_2;
}
}
int main(void)
{
printf("The final result is %d\n", fib(i));
return 0;
}