MahmudulMaruf

Code · Faith · Curiosity

Blog Post

Beecrwod: 1176 - Fibonacci Array

cpp �� 2023-08-16 12:45:00

cpp

Problem: 1176 - Fibonacci Array

Solution: 

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long i, j, sum=0, f1, f2, a[100];
    int n;
    for(i=0; i<61; i++)
    {
        if(i==0)
        {
            f1=0;
            a[0]=0;
        }
        else if(i==1)
        {
            f2=1;
            a[1]=1;
        }
        else
        {
        sum=f1+f2;
        f1=f2;
        f2=sum;
        a[i]=sum;
        }

    }
    int t;
        cin>>t;
        while(t--)
        {
            cin>>n;
            cout<<"Fib("<<n<<") = "<<a[n]<<endl;
        }
    return 0;
}




Post Visited: 711 times

Categories: cpp

0 Comments

    No comments yet. Be the first to comment!

Leave a comment

Captcha