Fibonacci Series Using Recursion in C

Get Certified in C Programming and Take Your Skills to the Next Level

Program 1

// Fibbonacci Series using recursion
// 0      1     1     2    3   5    8      13    24   ..... n 
#include<stdio.h>
#include<conio.h>
void fibbonacci(int);
int main()
{
      system("cls");
      int n;
      printf("Enter a number");
      scanf("%d",&n);
      fibbonacci(n);
      return 0;
}
void fibbonacci(int n)  // n=0
{
      static int a=-1,b=1,c;  // a=5 ,b=8  ,c 
      if(n==0)   
        return;
      else
      {
          c=a+b;   // c=13
          printf("%6d",c);     // 0   1    1    2    3      5       8    13 
          a=b; 
          b=c;
          fibbonacci(n-1);
      }  
}

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *