Count ways to reach the n’th stair

PROBLEM :
There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time. Count the number of ways, the person can reach the top (order does matter).

Input:
The first line contains an integer 'T' denoting the total number of test cases. In each test cases, an integer N will be given.

Output:
Print number of possible ways to reach Nth stair. Answer your output % 10^9+7.

Constraints:
1<=T<=1000
1<=N<=100

Example:
Input:
3
4
10
24

Output:
5
89
75025

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
#include<math.h>
long long Count_nth_stair(long long ) ;
int main()
 {
int t ;
long long no ;
cin>>t ;
while(t--)
{
   cin>>no ;
 
   no=Count_nth_stair(no) ;
   cout<<no<<endl ;
}
return 0;
}

long long Count_nth_stair(long long no)
{
    long long arr[no+1] ;
    int i ;
   
    arr[0]=1 ;
    arr[1]=1 ;
   
    for(i=2;i<=no;i++)
        arr[i]=(arr[i-1]+arr[i-2])%1000000007 ;

    return arr[no] ;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )