Fibonacci number

Report a typo

Recall the definition of Fibonacci sequence: F0=0,F1=1,Fn=Fn1+Fn2F_0 = 0, F_1 = 1, F_n = F_{n-1} + F_{n−2}, for n>1n \gt 1

Your goal in this problem is to find the last digit of 𝑛th𝑛-th Fibonacci number using a for loop. We've already written part of the logic to calculate the last digit; your task is to write the required additional code to finish the for loop declaration.

Recall that Fibonacci numbers grow exponentially. For example:

𝐹50=12586269025𝐹_{50} = 12586269025

Tip: If you're stuck, you can learn more about the Fibonacci sequence using the Fibonacci Calculator.

Sample Input 1:

50

Sample Output 1:

5

Sample Input 2:

15

Sample Output 2:

0
Write a program in Go
package main

import "fmt"

func main() {
// DO NOT delete this code block. It takes as an input the `n` value to be used in the for loop
var n int
fmt.Scanln(&n)

// DO NOT delete the variable declarations that will be used within the for loop!
var currentFib, previousFib = 1, 0
var lastDigit int

// Write the additional required code to finish the for loop declaration below:
for i := 0; ? < n; ?++ {
lastDigit = (? + previousFib) % 10
currentFib = ?
previousFib = lastDigit
}

fmt.Println(lastDigit) // This line outputs the calculated `lastDigit`
}
___

Create a free account to access the full topic