**You are climbing a stair case. It takes n steps to reach to the top.**

**Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?**

C++:

1 int numStep(int n)

2 {

3 int* A=new int[n+1];

4 A[0]=A[1]=1;

5 for(int i=2;i<=n;i++)

6 A[i]=A[i–1]+A[i–2];

7 return A[n];

8 }

2 {

3 int* A=new int[n+1];

4 A[0]=A[1]=1;

5 for(int i=2;i<=n;i++)

6 A[i]=A[i–1]+A[i–2];

7 return A[n];

8 }

Advertisements