The below code finds the Fibonacci series for the entered number of terms :
#include<iostream>
using namespace std;
main()
{
int n, c, a = 0, b = 1, temp;
cout << "Enter the number of terms" << endl;
cin >> n;
cout << "The Fibonacci series are :- " << endl;
for ( c = 1 ; c < n ; c++ )
{
if ( c <= 1 )
temp = c;
else
{
temp = a + b;
a = b;
b = temp;
}
cout << temp << endl;
}
return 0;
}
Input :
Enter the number of terms : 7
Output :
f =
1
f =
1 1
f =
1 1 2
f =
1 1 2 3
f =
1 1 2 3 5
f =
1 1 2 3 5 8
f =
1 1 2 3 5 8 13
If the above link doesn't work go to this URL :
http://gappcode.blogspot.in/2013/11/fibonacci-series.html
No comments:
Post a Comment