# Ladder of n steps is given.Find the number of ways to reach the end point.I can take either 1 step or two steps at a time

Ladder of n steps is given.Find the number number of ways to reach the end point.I can take either 1 step or two steps at a time

Here ways refer to various combination of 1s and 2s such that the total is n.

Suppose we have a 1s and b 2s.

Here a + 2b = n should always be true.

So we check for values of a and b such that both are non negative integers.

For each value of a and b we need to find their positions for which we use ^{(n-b)}C_{b}.

Example:

n = 5

So various combinations are:

b=0 , a=5 , ^{5}C_{0} = 1

1,1,1,1,1

b=1 , a = 3 , ^{4}C_{1} = 4

2,1,1,1

1,2,1,1

1,1,2,1

1,1,1,2

b=2 , a = 1 , ^{3}C_{2} = 3

2,2,1

1,2,2

2,1,2

Total count = 8

#include<stdio.h> //Function to find factorial of a number long factorial(int n) { int c; long result = 1; for (c = 1; c <= n; c++) result = result*c; return result; } //function to find nCr long find_ncr(int n, int r) { long result; result = factorial(n)/(factorial(r)*factorial(n-r)); return result; } int main(){ long n,b,count=0; printf("Enter number of stepsn"); scanf("%ld",&n); for(b=0;b<=n/2;b++){ //check if a is always greater than 0 if((n-(2*b)) >=0){ count+= find_ncr(n-b,b); } } printf("Number of ways to reach end point are : %ldn",count); return 0; }