www.cprogramming.tk

www.cprogramming.tk

Program to check Fibonacci number

A program that get a number from the user and check if it is a fibonacci number or not:

Program check if number is a part of

fibonacci sequence or fibonacci series

using namespace std;
#include<iostream>
#include<conio.h>
int main()
{
int a,b,next,n;
cout<<"Enter a number:";
cin>>n;
if((n==0)||(n==1))
  cout<<"Entered number is fibonacci number";
else
{
a=0;
b=1;
next=a+b;

while(next<n)
{
Output/Result
a=b;
b=next;
next=a+b;
    }
if(next==n)
 cout<<n<<" is fibonacci number";
else
 cout<<n<<" is not a fibonacci number";
    }
getch();
return 0;
}
Program to check Fibonacci number Program to check Fibonacci number Reviewed by Shoaib Jameel on 3/18/2017 03:15:00 pm Rating: 5

No comments:

Theme images by mariusFM77. Powered by Blogger.