My program allows to find fibonacci numbers at a certain position n using stack but when I type in a position after 76, the numbers start to get a single number off and larger from there. Here is my arithmetic:
for (int i = 2; i < nth; i++)
{
if (nth == 1)
return 1;
else if (nth == 2)
return 1;
else
n1 = fibStack.top();
fibStack.pop();
n2 = fibStack.top();
fibStack.pop();
temp = n1 + n2;
fibStack.push(n2);
fibStack.push(n1);
fibStack.push(temp);
}
I used double type and precision to output correctly. The correct output at 83 is: 99194853094755497 What my code outputs is: 99194863094755488