C program for Fibonacci series using recursion

1. C code to print Fibonacci series by recursion
2. Fibonacci series in c by using recursion

3. C code for Fibonacci series using recursion
4. Program to generate Fibonacci series using recursion in c

#include<stdio.h>

void printFibonacci(int);

int main(){

    int k,n;
    long int i=0,j=1,f;

    printf("Enter the range of the Fibonacci series: ");
    scanf("%d",&n);

    printf("Fibonacci Series: ");
    printf("%d %d ",0,1);
    printFibonacci(n);

    return 0;
}

void printFibonacci(int n){

    static long int first=0,second=1,sum;

    if(n>0){
         sum = first + second;
         first = second;
         second = sum;
         printf("%ld ",sum);
         printFibonacci(n-1);
    }

}

Sample output:

Enter the range of the Fibonacci series: 10
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34 55 89

C code to print Fibonacci series without recursion:

#include<stdio.h>

void printFibonacci(int);

int main(){

    int k,n;
    long int i=0,j=1,f;

    printf("Enter the range of the Fibonacci series: ");
    scanf("%d %d ",&n);

    printf("Fibonacci Series: ");
    printf("%d ",0);
    printFibonacci(n);

    return 0;
}

void printFibonacci(int n){

    long int first=0,second=1,sum;

    while(n>0){
         sum = first + second;
         first = second;
         second = sum;
         printf("%ld ",sum);
         n--;
    }
}





Sum of n numbers using recursion in c
Matrix multiplication using recursion in c
Multiplication using recursion in c
Lcm using recursion in c
Using recursion in c find the largest element in an array
Prime number program in c using recursion
Decimal to binary conversion in c using recursion
C program for fibonacci series using recursion
Reverse a string using recursion
Write a program for palindrome using recursion
Find factorial of a number using recursion in c program
Find gcd of a number using recursion in c program
Find sum of digits of a number using recursion using cprogram
Find power of a number using recursion using c program
Binary search through recurssion using c program
Reverse a number using recursion in c program
Big list of c program examples

6 comments:

  1. void main()
    {
    int a,b,c,i,n;
    a=0;
    b=1;
    printf("Enter number of terms of the series to be generated:");
    scanf("%d",&n);
    if(n==1)
    {
    printf("\n FIBONACCI SERIES\n");
    printf("%d",a);

    }
    else if(n==2)
    {
    printf("\n FIBONACCI SERIES\n");
    printf("%d\t%d",a,b);

    }
    else
    {
    printf("%d\t%d",a,b);
    for(i=3;i<=n;i++)
    {
    c=a+b;
    a=b;
    b=c;
    printf("\t%d",c);

    }
    }
    getch();
    }

    OR

    void main()
    {
    int a,b,c,i,n;
    clrscr();
    a=0;
    b=1;
    printf("\n enter n for how many times generate series");
    scanf("%d",&n);
    printf("\n FIBONACCI SERIES\n");
    printf("\t%d\t%d",a,b);
    for(i=0;i<n;i++)
    {
    c=a+b;
    a=b;
    b=c;
    printf("\t%d",c);
    }
    getch();
    }

    ReplyDelete
  2. Find non fibonesis serize using function

    ReplyDelete
  3. #include
    #include
    Void main( )
    {
    Int n, i, c, a = 0, b = 1;

    printf(“Enter Fibonacci series of n’th term”);
    scanf(“%d”, & n);
    printf(“%d%d”, a, b);
    for ( i = 0; I <= (n-3); i++)
    {
    c = a + b
    a = b
    b = c
    printf(“%d”,c);
    }
    getch( );
    }

    Out put:
    Enter the Fibonacci series of n’th term : 7
    0112358

    ReplyDelete
  4. //in c++
    //this is short code of Fibonacci function in recursion..

    int fib(int n){

    if(n==0){
    return 0;
    }else if(n==1){
    return 1;
    }else{

    return fib(n-1)+fib(n-2);
    }
    }

    Void main( )
    {

    cout<<fib(n)<<endl;

    }

    ReplyDelete
  5. How can I tell if a given source code has used recursion or not, when there is a function declared?

    ReplyDelete
  6. This is really helpful.
    For Dynamic Programming this seems 2 be d brief one...

    ReplyDelete