#include<iostream.h>
void fibonacci(int n); //function declaration
int main()
{
int n; //variable declaration
cout<<"Please enter a valid 'n' value"<<endl;
cin>>n; //reading 'n' value
while(n<1) //validating 'n' value
{
cout<<"You have entered a invalid Number"<<endl;
cout<<"Please enter a valid Integer"<<endl;
cin>>n;
}
cout<<"Fibonacci serice upto 'n'th term is :"<<endl;
fibonacci(n); //calling function
return 0;
}
void fibonacci(int n) //called function
{
int f1=0,f2=1,fib,i; //variable declaration and Initialization
for(i=1;i<=n;++i)
{
cout<<f1<<endl; //to print the series
fib=f1+f2;
f1=f2;
f2=fib;
}
}
void fibonacci(int n); //function declaration
int main()
{
int n; //variable declaration
cout<<"Please enter a valid 'n' value"<<endl;
cin>>n; //reading 'n' value
while(n<1) //validating 'n' value
{
cout<<"You have entered a invalid Number"<<endl;
cout<<"Please enter a valid Integer"<<endl;
cin>>n;
}
cout<<"Fibonacci serice upto 'n'th term is :"<<endl;
fibonacci(n); //calling function
return 0;
}
void fibonacci(int n) //called function
{
int f1=0,f2=1,fib,i; //variable declaration and Initialization
for(i=1;i<=n;++i)
{
cout<<f1<<endl; //to print the series
fib=f1+f2;
f1=f2;
f2=fib;
}
}
No comments:
Post a Comment