If you have a N steps staircase and you are standing at 1 step now you have options to step up to 2step or you can skip one step and go to 3rd step... so at ith step you have a option to go to i+1 step or i+2 step. So how many ways you can climb the stairs?
Click for Solution

  • Warning: Illegal string offset 'name' in /home/prepdo6/gpl4you/discussquessub.php on line 681
    A I guess the solution provided is wrong. It should be

    int a=1,b=1,c;
    for(int i=2;i<n;i++){
    c=a+b;
    a=b;
    b=c;
    }
    System.out.println(b);

    for n=5 cases = 5 and for n=6 cases=8

    CpjJwWHV   Hmm, Its fibonacci numbers:
    Let f(n) denote the number of ways to reach nth step. You can reach nth step from step n-1 or n-2 i.e. no. of ways to reach step is the sum
    of number of steps required to reach step n-1 and n-2. So,

    F(n) = F(n-1] + F(n-2)
    which is nothing but the fib. no series.
    14 years ago
    CpjJwWHV   that's right way...
    12 years ago
    CpjJwWHV   but take f(1)=1;f(2)=1;
    12 years ago

    Smiley

[Insert Code]