## What is Fibonacci Series

In mathematics, the Fibonacci numbers, often known as **F _{n}**, form a series in which each number is the sum of the two numbers before it.

The Fibonacci numbers were originally mentioned in Indian mathematics in Pingala’s work on listing potential Sanskrit poetry patterns made up of syllables of two lengths, which was completed in 200 BC.

They were first used in Western European mathematics in the book Liber Abaci, published in 1202, by the Italian mathematician Leonardo of Pisa, afterwards known as Fibonacci.

Every term in a Fibonacci series is the sum of the previous two terms.

## Fibonacci Series Formula

The missing words in a Fibonacci series can be located using the mathematic formula for the series.

The Fibonacci series’s first two terms are 0 and 1. It will go to infinity. Some older versions of Fibonacci removed 0 from the series, but the original Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13,…..

For finding the (n+1)^{th }term in series, we need to use this recursive formula :-

**F _{n} = F_{n-1} + F_{n-2 } ,Where n > 1;**

The value of n is always greater than 2 because F0 and F1 are provided by default. First term F_{0} is 0 and second term F_{1} is 1 afterward F_{2} is found from the Fibonacci Formula.

F2 = F1 + F0 = 0 + 1 = 1

F3 = F2 + F1 = 1 + 1 = 2

## Program of Fibonacci Series

```
#include <stdio.h>
int main()
{
int n, t1 = 0, t2 = 1;
int nextTerm = t1 + t2; //initialize all integers
printf("Enter the number of terms: ");
scanf("%d", &n); // take input from user
if(n == 1)
{
printf("Fibonacci Series: %d", t1);
}
else if(n == 2)
{
printf("Fibonacci Series: %d, %d, ", t1, t2);
}
else
{
printf("Fibonacci Series: %d, %d, ", t1, t2);
}
for (int i = 3; i <= n; ++i)
{
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
```

```
#include <iostream>
using namespace std;
int main()
{
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i) {
// Prints the first two terms.
if(i == 1)
{
cout << t1 << ", ";
continue;
}
if(i == 2)
{
cout << t2 << ", ";
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
cout << nextTerm << ", ";
}
return 0;
}
```

```
import java.util.*;
class Main
{
public static void main(String[] args)
{
int firstTerm = 0, secondTerm = 1; //initialization
Scanner s = new Scanner(System.in);
System.out.println("Enter the number of terms: ");
int n = s.nextInt();
System.out.println("Fibonacci Series: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(firstTerm + ", ");
int nextTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = nextTerm;
}
}
}
```

```
totalTerms = int(input("Enter the number of terms: "))
n1, n2 = 0, 1
count = 0
if totalTerms == 1:
print("Fibonacci sequence upto",totalTerms,":")
print(n1)
else:
print("Fibonacci Series:")
while count < totalTerms:
print(n1)
nth = n1 + n2
n1 = n2 #Update value here
n2 = nth
count += 1
```