Program to check if the digit entered is a part of fibonacci series stating from 0,1…that is 0,1,1,2,3,5,…I tried it like this:-
#include
using namespace std;
int main()
{
int a,b=0,c=1,i=1,d;
cout<<"Enter number ";
cin>>a;
if(a==0)
{
cout<<“yes”;
}
while(i<=a)
{
d=b+c;
if(a==b+c)
{
cout<<“yes”;
break;
}
b=c;
c=d;
i++;
}
if(i==a+1)
{
cout<<“NO”;
}
}
I have a doubt, this program is giving the desired output but actually i am confused that how much time i need to operate the loop, in above program i checked untill i becmes a but in real it is not necessary to check uptill a, we can stop checking before that… so where can we stop checking… and also is there any other way out for this program.??