This is the C++ program I've written to get fibonacci numbers from 1 to 100.
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main()
{
int n;
vector<double> f;
//adding first two fibonacci numbers to vector
f.push_back(0);
f.push_back(1);
cout<<"How many fibonacci numbers do you want : ";
cin>>n;
for(int i=0; i<n; i++)
{
if(i>1) f[i] = f[i-1] + f[i-2];
cout<<(i+1)<<": "<<fixed<<setprecision(0)<<f[i]<<endl;
}
}
All the results are correct upto 79 values but then after the 80th value is not exactly the sum of 78 and 79 values. The output is:
....
78: 5527939700884757
79: 8944394323791464
80: 14472334024676220
....
Here the last digit should be 1 but it shows 0, why did this happen?