Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

What is the Fibonacci Series with explanation and program

YASH PAL, 14 January 202128 May 2024

Fibonacci series is a series in which we have given the first two numbers and the next number sequence can be found using the sum of the two preceding ones. it is denoted by Fn. and the number in the Fibonacci series is called Fibonacci numbers. 

This series is named for Leonardo Pisano an Italian mathematician. In Mathematics Fibonacci sequence is defined as

a1 = 0, a2 = 1 and an = (an-1) + (an-2) where (n > 2)

so the Fibonacci sequence is a series of numbers

what is fibonacci series
Fibonacci series

Here

  • the 3rd number is found by adding the two numbers before it (0 + 1).
  • the 4th number is found by adding the two numbers before it (1 + 2) and soon.

Note – In modern mathematics, we can’t include 0.

Fibonacci was not the first to know about the sequence, it was known in India hundreds of years before it appears in the Sanskrit prosody.

Use of the Fibonacci series in Real life

  1. When we make squares with those widths, we get a nice spiral. and this spiral is found in nature too.
  2. It is also used in coding and programming languages to solve practical problems.
  3. one of the main applications of Fibonacci numbers is in the area of stock market analysis. we use it to estimate the price of a particular stock.
  4. It is used to calculate the population of bees or rabbits.
  5. It is also used to estimate the complexity of a task.
  6. It is also used in mathematics to find solutions like Pascal’s triangle and Pythagorean triples.

One of the major facts is that when we calculate the ratio of two consecutive numbers then it is very close to the Golden Ratio. the bigger the pair of Fibonacci numbers the close the approximations to the golden ratio.

First 10 Fibonacci numbers

let’s say  a1 =  a2 = 1 and to find the first 10 numbers we are going to use the formula (an-1) + (an-2) where (n > 2). always remember we need to have the first two numbers if we want to find the other sequence of the Fibonacci series.

a1 = 1 = a2

a3 = 1 + 1 = 2

a4 = 1 + 2 = 3

a5 = 2 + 3 = 5

a6 = 3 + 5 = 8

a7 = 5 + 8 = 13

a8 = 8 + 13 = 21

a9 = 13 + 21 = 34

a10 = 21 + 34 = 55

Program in C Programming

#include <stdio.h>

int main()
{
    int a1 = 1;
    int a2 = 1;
    int s, next;
    int i = 1;
    
    printf("Enter length of fibonacci series: ");
    scanf("%d", &s);
    printf("%d\n%d \n", a1, a2);
    
    for(i;i<s;i++){
        next = a1 + a2;
        printf("%d \n", next);
        a1 = a2;
        a2 = next;
        next = 0;
    }

    return 0;
}

Program in C++ Programming

#include <stdio.h>

int main()
{
    int a1 = 1;
    int a2 = 1;
    int s, next;
    int i = 1;
    
    printf("Enter length of fibonacci series: ");
    scanf("%d", &s);
    printf("%d\n%d \n", a1, a2);
    
    for(i;i<s;i++){
        next = a1 + a2;
        printf("%d \n", next);
        a1 = a2;
        a2 = next;
        next = 0;
    }

    return 0;
}

Program in Java programming

import java.util.*; 

public class random {

    public static void main(String[] args) {

        int i = 1, t1 = 0, t2 = 1;
        System.out.print("Enter length of Series: ");
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        System.out.print("First " + n + " terms: ");

        while (i <= n)
        {
            System.out.print(t1 + "\n ");

            int sum = t1 + t2;
            t1 = t2;
            t2 = sum;

            i++;
        }
    }
}

Program in Python Programming

n = int(input("How many terms? "))

n1, n2 = 0, 1
count = 0

if n <= 0:
   print("Please enter a positive value")
elif n == 1:
   print("Fibonacci sequence upto",n,":")
   print(n1)
else:
   print("Fibonacci sequence:")
   while count < n:
       print(n1)
       nth = n1 + n2
       n1 = n2
       n2 = nth
       count += 1

Read other Tutorials

  • A simple model of a computer system
  • Binary Number System
Basic Programming Tutorials Programming Tutorials Basic Programmingcomputer science

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
©2025 Programming101 | WordPress Theme by SuperbThemes