I think I there is some problem in implementation of my loop! Here's my code.
#include <iostream>
using namespace std;
int main()
{
int i=2;
long long int FiboNo[100];
FiboNo[0] = 1;
FiboNo[1] = 2;
do{
FiboNo[i]=FiboNo[(i-1)]+FiboNo[(i-2)];
cout<<FiboNo[i]<<endl;
i++;
}while(FiboNo[i]<4000000);
return 0;
}
You are incrementing
i
before you compare.is what you want to do.
Here's what's happening:
This has no problem, when
fibo[someIndex]
reaches the limit. It wont come out, because your value is always a0
.