fibonacci number series using function and recursion in c program

fibonacci number  series print  using function and recursion :


In this program, we will read value of N (N for number of terms) and then print fibonacci series till N terms using recursion.
Fibonacii series: Is a series of number in which each number is the sum of preceding two numbers.

0 1 1 2 3 5 8 ...


Fibonacci series in C programming: C program for Fibonacci series using a loop and recursion. Using the code below you can print as many terms of the series as required. Numbers of this sequence are known as Fibonacci numbers. The first few numbers of the series are 0, 1, 1, 2, 3, 5, 8, ...,. Except for the first two terms of the sequence, every other term is the sum of the previous two terms, for example, 8 = 3 + 5 (addition of 3 and 5).


Required knowledge






Example 

Input : 5
Output : 0 1 1 2 3



Code :




#include<stdio.h>

int fibonacci(int n)
{
    if(n==0)
    return 0;
    else if(n==1)
        return 1;
      return (fibonacci(n-1)+ fibonacci(n-2));
}
int main()
{
    int n,i;
    int bbb;
    printf("Enter the number ");
    scanf("%d",&n);
    for(i=0;i<n;i++){
    bbb=fibonacci(i);
    printf("%d ",bbb);
    }


    return 0;
}






Output : 









Required pic 






No comments

Powered by Blogger.