Fibonacci Series in C – Write a program in C to print Fibonacci series

Fibonacci Series in C – Program

#include <stdio.h>
#include<conio.h>

int main()
{
    int first_term=0, second_term=1, next_term, i, n;
    printf("Welcome to https://bptutorials.com \n");
    printf("Enter no. of terms you want in Fibonacci Series:");
    scanf("%d", &n);
    printf("First %d term of Fibonacci series :", n);
    for(i=0; i<n; i++)
    {
        if(i<= 1)
        {
            next_term = i;
        }
        else
        {
            next_term = first_term+second_term;
            first_term = second_term;
            second_term = next_term;
        }
        printf(" %d ", next_term);
    }

    getch();
}

Output:

Fibonacci series in C

Fibonacci series using recursion in C

#include <stdio.h>
int fibonacci (int term);
 int fibonacci (int term)
   {
       if(term < 2)
       return term;
       // Recursive call
       return (fibonacci(term-1) + fibonacci(term-2));
   }

int main()
{
   int i, n;
   printf("Welcome to https://bptutorials.com \n");
   printf(" Enter the no of terms in Fibonacci series : ");
   scanf("%d", &n);
   printf("Fibonacci series of %d terms is : ", n);
   for(i=0; i<n; i++)
   {
       printf("%d ", fibonacci(i));
   }
   
  
}

Output

Fibonacci series using recursion in C
Fibonacci series using recursion in C
Share This!

Leave a Reply

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