Program to find the Fibonacci value of any given number from 0 to infinity.
#include<iostream.h>
#include<conio.h>
void main()
{
double num,f0,f1,f2;
cout<<"Enter a number to find Fibonacci value : ";
cin>>num;
if(num==0)
{
cout<<"0";
getch();
getch();
return;
}
if(num==1)
{
cout<<"1";
getch();
getch();
return;
}
f0=0;
f1=1;
for(int i=2;i<=num;i++)
{
f2=f0+f1;
f0=f1;
f1=f2;
}
cout<<f2;
getch();
}
No comments:
Post a Comment