TechoSagar: Check if the number is Fibonacci

Search

Google Alert - jobs

Check if the number is Fibonacci

Check if a given number is Fibonacci number. Fibonacci number is a number which occurs in Fibonacci series.
Input:
The first line of input contains an integer T denoting the number of test cases.
Each test case contains a number.

Output:
Print "Yes" if the entered number is Fibonacci number else "No".
 
Constraints:
1<=t<=100
1<=n<=100

Example:

Input
2
34
41
Output
Yes

No
Your Code
#include<iostream>

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int i;
int x=0,y=1,number=1, result;
  while(number<=n)
{  //cout<<number<<" ";
 result=number;
number=x+y;
x=y;
y=number;
}
if(result==n)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}

Follow us

Follow Bijendra Kumar on Facebook