- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Alternate Fibonacci Numbers in C++

**Fibonacci Number** is defined as a sequence of numbers that starts with two fixed numbers, generally, **o,1** or **1, 1** and the successive elements of the sequence are the sums of the previous two numbers of the sequence.

For example, Fibonacci series till 8 elements is 0,1,1,2,3,5,8,13,21,34,55,89.

Now, let's generalize this series. Here, the value of the nth term is equal to the sum of (n-1)th and (n-2)th term. So, let's get the mathematical derivation of the formula for the nth term of the Fibonacci series.

T_{n} = T_{n-1} + T_{n-2}

Using this formula to find out the 5th term of the Fibonacci series, we have the 3rd and 4th term given.

T_{5} = T_{4} + T_{4}

T_{5} = 3 + 5 = 8.

**Alternate Fibonacci series** is a Fibonacci series that has values the same as the Fibonacci series but alternate elements are to be printed in the series. For example, the first 4 elements of the alternate Fibonacci series are 0, 1 , 3, 8.

To create a program to print alternate Fibonacci series, we will use the formula and for every element of the series and then print only alternate values of the series.

## Algorithm

Step 1 : Initialize the first two values of the series n1 = 0 and n2 = 1. Step 2 : loop from i = 2 to n and follow 3-5 : Step 3 : next element is n3 = n1 +n2 Step 4 : n1 = n2 and n2 = n3 Step 5 : if i%2 == 0 : print n3

## Example

#include <iostream> using namespace std; int main(){ int n1=0,n2=1,n3,i,number; cout<<"Enter the number of elements to be present in the series: "; cin>>number; cout<<"Alternate Fibonacci Series is : "; cout<<n1<<" "; for (i=2;i<(number*2);++i){ n3=n1+n2; n1=n2; n2=n3; if(i%2==0) cout<<n3<<" "; } return 0; }

## Output

Enter the number of elements to be present in the series: 4 Alternate Fibonacci Series is : 0 1 3 8

- Related Questions & Answers
- Large Fibonacci Numbers in C#
- Python Program for Fibonacci numbers
- Prime numbers and Fibonacci in C++
- Program for Fibonacci numbers in C
- Checking for Fibonacci numbers in JavaScript
- Program for Fibonacci numbers in PL/SQL
- Sum of squares of Fibonacci numbers in C++
- C++ Program to Find Fibonacci Numbers using Recursion
- C++ Program to Find Fibonacci Numbers using Iteration
- C++ Program to Find Fibonacci Numbers using Dynamic Programming
- C++ Program to Find Fibonacci Numbers using Matrix Exponentiation
- How to print the first ten Fibonacci numbers using C#?
- Alternate bits of two numbers to create a new number in C++
- Find the GCD of N Fibonacci Numbers with given Indices in C++
- Alternate Key in RDBMS