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 |
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
Reviewed by Alpha
on
3/18/2017 03:15:00 pm
Rating:
No comments: