A Fibonacci number is a memeber of a set in which each
number is the sum of the previous two numbers.( The Fibonacci series
describe a form of a spiral) The series begins
0, 1, 1, 2, 3, 5, 8, 13, 21, ....
Write a program that calculate and prints nth term of Fibonacci series.
Source Code:
Result:
number is the sum of the previous two numbers.( The Fibonacci series
describe a form of a spiral) The series begins
0, 1, 1, 2, 3, 5, 8, 13, 21, ....
Write a program that calculate and prints nth term of Fibonacci series.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream.h> #include <conio.h> int main() { int n, c, fib1 = 0, fib2 = 1, fib3; cout << " Enter the number of terms of Fibonacci series" << endl; cin >> n; cout << "First " << n << " terms of Fibonacci series are: " << endl; for ( c = 0 ; c < n ; c++ ) { if ( c <= 1 ) fib3 = c; else { fib3 = fib1 + fib2; fib1 = fib2; fib2 = fib3; } cout << fib3 << endl; } getch(); return 0; } // main |
Result:
Enter the number of terms of Fibonacci series 7 First 7 terms of Fibonacci series are: 0 1 1 2 3 5 8
No comments:
Post a Comment