Fibonacci Between

Given two numbers L and R, you must print all the Fibonacci numbers between L and R (inclusive). Alt…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

Here is a simple solution in C++

#include<iostream>
using namespace std;

int main(){
    long long L,R;
    cin >> L >>R;
    long long first=0,second=1,result=0;
    if(L==0){
        cout<<0<<endl;
    }
    while(result<=R){
        result =first+second;
        first = second;
        second = result;
        if(result>=L and result<=R){
            cout << result << endl;
        }
    }
}