Dev Skill DCP-184: Easy Sequence Solution

Problem Link
Dev Skill DCP-184: Easy Sequence Solution
#include<bits/stdc++.h>
using namespace std;
void sequence(int n)
{
    int a=1,b=3,c=3;
    if(n==1)
        cout<<1<<endl;
    else if(n==2)
        cout<<3<<endl;
    else
    {
        for(int i=3;i<=n;i++)
        {
            b=a+b;
            a=c;
            c=b;
        }
        cout<<b<<endl;
    }
}
int main()
{
    int n,t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        sequence(n);
    }
    return 0;
}

No comments

Theme images by enjoynz. Powered by Blogger.