Homework program doubt

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.??

@Sheenagoyal21
You can run your loop till d<=a. This will ensure we only iterate till our computed values are smaller than a.
Also this method is fine. However if you wish to work for multiple testcases , you can store the Fibonacci Sequence till a certain number in an array and then implement binary search on it to check.
But since you are working for a single testcase program , this is fine.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

In general, there are many different sources where you can find what you are looking for, but I know one that will certainly help you solve this problem. Anyway, copywriting really helps in the development of websites, blogs and various types of business. Consequently, I would like to highlight this resource https://assigncode.com/ where there is write code for me. I assume that you will definitely solve your difficulty.