Given a number n, the task is to write a program in C++ to print the n-terms of Fibonacci Series using a Class template
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
Input: n = 2 Output: 0, 1 Input: n = 9 Output: 0, 1, 1, 2, 3, 5, 8, 13, 21
- Create a class for the Fibonacci Series
- Take the first two terms of the series as public members a and b with values 0 and 1, respectively.
- Create a generate() method in this class to generate the Fibonacci Series.
- Create an object of this class and call the generate() method of this class using that object.
- The Fibonacci Series will get printed.
Below is the implementation of the above approach:
0 1 1 2 3 5 8 13 21
- C Program to print Fibonacci Series without using loop
- Print Fibonacci Series in reverse order
- 3 Different ways to print Fibonacci series in Java
- C/C++ Program for nth multiple of a number in Fibonacci Series
- Check if a M-th fibonacci number divides N-th fibonacci number
- Check if sum of Fibonacci elements in an Array is a Fibonacci number or not
- Python | Find fibonacci series upto n using lambda
- Program to print first n Fibonacci Numbers | Set 1
- Program to print Fibonacci Triangle
- Print first n Fibonacci Numbers using direct formula
- Print Fibonacci sequence using 2 variables
- n'th multiple of a number in Fibonacci Series
- Factorial of each element in Fibonacci series
- Find n terms of Fibonacci type series with given first two terms
- Sum of nth terms of Modified Fibonacci series made by every pair of two arrays
- K- Fibonacci series
- Find the Nth element of the modified Fibonacci series
- Last digit of sum of numbers in the given range in the Fibonacci series
- Check whether Array represents a Fibonacci Series or not
- Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.