Easy csharp

Fibonacci 5 (DP) #81

Problem

Print Fibonacci number F(5).

Hints
  • Rolling two variables

Your solution

TestStatusDetails
Ready — edit the code above and click Run or Submit.

Solution

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = 5;
        int a = 0, b = 1;
        for (int k = 0; k < n; k++) { int t = a + b; a = b; b = t; }
        Console.WriteLine(a);
    }
}

Try solving on your own first, then reveal the official answer.

Explanation

Bottom-up DP for Fibonacci.

Discussion

0

Sign in to join the discussion.

No discussions yet — ask the first question!

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details