Reach the Nth point
PROBLEM :
There are N points on the road ,you can step ahead by 1 or 2 . Find the number of ways you can reach at point N. For example: for n=4 we have 5 possible ways [1,1,1,1] [1,1,2] [1,2,1] [2,1,1] [2 2].
Input:
The first line of input contains an integer T denoting the number of test cases.Next line of each input contains a single integer N.
Output:
Print the output of each test case in a new line.
Constraints:
1<=T<=100
1<=N<=90
Example:
Input:
2
4
5
Output:
5
8
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
long long Reach_Nth_point(long long ) ;
int main()
{
int t ;
long long no ;
cin>>t ;
while(t--)
{
cin>>no ;
no=Reach_Nth_point(no) ;
cout<<no<<endl ;
}
return 0;
}
long long Reach_Nth_point(long long no)
{
no=no+1 ;
long long arr[no] ;
int i ;
arr[0]=0 ;
arr[1]=1 ;
for(i=2;i<=no;i++)
arr[i]=arr[i-1]+arr[i-2] ;
return arr[no] ;
}
---------------------------------------------------------------------------------
There are N points on the road ,you can step ahead by 1 or 2 . Find the number of ways you can reach at point N. For example: for n=4 we have 5 possible ways [1,1,1,1] [1,1,2] [1,2,1] [2,1,1] [2 2].
Input:
The first line of input contains an integer T denoting the number of test cases.Next line of each input contains a single integer N.
Output:
Print the output of each test case in a new line.
Constraints:
1<=T<=100
1<=N<=90
Example:
Input:
2
4
5
Output:
5
8
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
#include<iostream>
using namespace std;
long long Reach_Nth_point(long long ) ;
int main()
{
int t ;
long long no ;
cin>>t ;
while(t--)
{
cin>>no ;
no=Reach_Nth_point(no) ;
cout<<no<<endl ;
}
return 0;
}
long long Reach_Nth_point(long long no)
{
no=no+1 ;
long long arr[no] ;
int i ;
arr[0]=0 ;
arr[1]=1 ;
for(i=2;i<=no;i++)
arr[i]=arr[i-1]+arr[i-2] ;
return arr[no] ;
}
---------------------------------------------------------------------------------
inimprinni Yolanda Logan https://www.harlingac.com/profile/Serato-Dj-Intro-En-Francais-REPACK/profile
ReplyDeletetairehyra