C Program to print Fibonacci Series using recursion !!

January 18, 2025 2 Comments » Hits : 338





Back to Basics : Fibonacci Series

  • In the 12th century, Leonardo Fibonacci discovered a simple numerical series Called Fibonacci Series.
  • Starting with 0 and 1, each new number in the series is simply the sum of the two before it.
  • To watch more about Fibonacci series - Click on this Video. It will Explain everything about this series.

C Program to print Fibonacci Series using recursion !!

#include<stdio.h>
    #include<conio.h>
    int size;
    int fibonacci (int prev_number, int number);
    void main()
    {
        static int prev_number=0,number=1;
        clrscr();
        printf("Enter the Size of Series (< 20) : ");
        scanf("%d",&size);
        printf("1 ");
        fibonacci (prev_number,number);
        getch();
    }
    int fibonacci (int prev_number, int number)
    {
    static int i=1;
    int next_num;
    if (i==size)
       return(0);
    else
        {
         next_num=prev_number+number;
         prev_number=number;
         number=next_num;
         printf ("%d ",next_num);
         i++; // increment counter
         fibonacci (prev_number,number); //recursion
        }
    return(0);
    }

Output :

Enter the Size of Series (< 20) : 6
1 1 2 3 5 8 13

Incoming search terms:

  • http://www.currentpostagerates.org postage rates

    I was never a fan of pointer arithmetic in C. It made code more difficult to read and understand which array index we were looking at IMHO.

  • saikiran

    Nice collection of programmes..I have been searching for this type of C programs.
    At last i found here thank you