// terms wise
// first you have to enter test case then the nth term
// eg 2
// 3 4
#include<iostream>
using namespace std;
int main()
{
long int n,t;
cin>>t;
for(int j=0;j<t;j++)
{
cin>>n;
int a=0,b=1;
unsigned int sum=0;
if(n==1)
cout<<a;
else if(n==2)
cout<<b;
else
{
for(int i=0;i<n-2;i++)
{
sum=a+b;
a=b;
b=sum;
}
cout<<sum<<"\n";
}
}
return 0;
}
// first you have to enter test case then the nth term
// eg 2
// 3 4
#include<iostream>
using namespace std;
int main()
{
long int n,t;
cin>>t;
for(int j=0;j<t;j++)
{
cin>>n;
int a=0,b=1;
unsigned int sum=0;
if(n==1)
cout<<a;
else if(n==2)
cout<<b;
else
{
for(int i=0;i<n-2;i++)
{
sum=a+b;
a=b;
b=sum;
}
cout<<sum<<"\n";
}
}
return 0;
}
No comments:
Post a Comment