Fibonacci Series Number in C++ using While Loop

Fibonacci Series: It is a series of numbers where the next term in series is the sum of the previous two numbers.

Fibonacci Series: 0 1 1 2 3 5 8 13 …

Fibonacci Series Number in C++ using While Loop

#include <iostream>
using namespace std;
int main()
{
     int n,a,b,next;
     cout<<"Enter a number to check if it is a Fibonacci Number: ";
     cin>>n;  
     if(n==0||n==1) 
     cout<<n<<" is a fibonacci number\n\n"; 
     else
     a=0;b=1;   
     next=a+b;     
     while(next<n)  
     {
        a=b;     
        b=next;   
        next=a+b;  
                    
     }
     if(next==n)    
    cout<<n<<" is a fibonacci number";    
    else
    cout<<n<<" is not a fibonacci number"; 
    return 0;
}

Output of Program

Enter a number to check if it is a Fibonacci Number: 10
10 is not a fibonacci number