Results 1 to 3 of 3

Thread: C code for Fibonacci series using recursion

  1. #1
    LewisClark is offline Senior Member
    Join Date
    Dec 2009
    Posts
    260
    Rep Power
    3

    Default C code for Fibonacci series using recursion

    Hi. I am last year computer science student. I am learning C programming language. I have to generate Fibonacci series using recursion. If you are having the code to perform the same then let me know about it. Thanks in advanced.

  2. #2
    WalkerCook is offline Senior Member
    Join Date
    Dec 2009
    Posts
    253
    Rep Power
    3

    Default

    Hi, hope this helps..

    Code:
    #include<stdio.h> 
    #include<conio.h> 
    int fib(int); 
    int f=1,j=0,k=0,i=0,c; 
    void main() 
    { 
    int l; 
    clrscr(); 
    printf("Enter limitn"); 
    scanf("%d",&l); 
    f=0; 
    printf("%dn",f); 
    f=1; 
    printf("%dn",f); 
    for(c=0;c<l;c++) 
    { 
    f=fib(l); 
    printf("%dn",f); 
    } 
    getch(); 
    } 
    int fib(int n) 
    { 
    
    while(i<n) 
    { 
    if(i<=n) 
    { 
    i++; 
    j=k; 
    k=f; 
    f=k+j; 
    fib(1); 
    return f; 
    } 
    } 
    
    }
    I have tried the given code but it didn’t solve my problem. Please try to provide some other solution.

  3. #3
    PerezMorris is offline Senior Member
    Join Date
    Dec 2009
    Posts
    250
    Rep Power
    3

    Default

    The script that I have mentioned will definitely help you. It is very simple code.

    Code:
    main()
    {
    int c=1,f=0,s=1;
    int i;
    printf("%d%20dn",f,f);
    printf("%d%20dn",s,s);
    for (i=2; i<5||f<s; i++)
    {
    c=f+s;
    f=s;
    s=c;
    printf("%d%20dn",i,c);
    }
    }

Similar Threads

  1. C code for Fibonacci series:
    By PerezMorris in forum Programming
    Replies: 3
    Last Post: 05-15-2010, 11:40 AM
  2. Fibonacci series in java
    By PerezMorris in forum Programming
    Replies: 2
    Last Post: 05-12-2010, 01:43 PM
  3. Recursion in C++
    By Steve Harlow in forum Programming
    Replies: 0
    Last Post: 11-26-2009, 12:39 PM
  4. Hot Code Replacement
    By ostin55 in forum Programming
    Replies: 0
    Last Post: 07-30-2008, 06:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48