1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

General formula for Code

Discussion in 'C' started by eblack10, Nov 16, 2010.

  1. eblack10

    eblack10 New Member

    Joined:
    Nov 16, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    C code
    Code:
    int f(int n)
    {
    return(0);
    if(n==1)
    return(1);
    printf("ADD");
    return(f(n-1)+f(n-2));
    }
    
    What general formula can you derive from this if someone was to use f(n)?
     
  2. ihatec

    ihatec New Member

    Joined:
    Sep 1, 2010
    Messages:
    20
    Likes Received:
    3
    Trophy Points:
    0
    Sorry but your code will stop execution at first line, but I suppose you want to obtain recursive algorithm for n-th Fibbonacci number.
     
    eblack10 likes this.
  3. eblack10

    eblack10 New Member

    Joined:
    Nov 16, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    That is what I thought. I was argued down that it should compile. Thanks!
     
  4. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    It will compile, but should have a warning about unreachable code.

    Jim
     

Share This Page