----------------------------------------------------------------------------------------------------------------------
Fibonacci Series Without Recursion Try It🔻
----------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
long n,first=0,second=1,third;
cout<<"Input the number of terms for Fibonacci Series : ";
cin>>n;
cout<<"\nFibonacci Series for the given number of terms : "<<first<<" "<<second;
for(int i=2;i<n;++i)
{
third=first+second;
cout<<" "<<third;
first=second;
second=third;
}
return 0;
}
----------------------------------------------------------------------------------------------------------------------
OUTPUT Try It🔻
----------------------------------------------------------------------------------------------------------------------
Input the number of terms for Fibonacci Series : 15
Fibonacci Series for the given number of terms : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
Fibonacci Series Without Recursion Try It🔻
----------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
long n,first=0,second=1,third;
cout<<"Input the number of terms for Fibonacci Series : ";
cin>>n;
cout<<"\nFibonacci Series for the given number of terms : "<<first<<" "<<second;
for(int i=2;i<n;++i)
{
third=first+second;
cout<<" "<<third;
first=second;
second=third;
}
return 0;
}
----------------------------------------------------------------------------------------------------------------------
OUTPUT Try It🔻
----------------------------------------------------------------------------------------------------------------------
Input the number of terms for Fibonacci Series : 15
Fibonacci Series for the given number of terms : 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377