Last active
February 10, 2021 20:56
-
-
Save jonathan-fielding/9720d9cb2c7d0a58da3bd799aa265c27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
var nth int | |
// Print our request to the user | |
fmt.Println("Enter Fibonacci number you require?") | |
// Request an number from the user and store it | |
// in the nth variable | |
fmt.Scanf("%d", &nth) | |
// Define our starting point | |
var lastNumber int = 0 | |
var currentNumber int = 1 | |
// Define a temporary store of the value for | |
// when we are shifting along the sequence | |
var nextNumber int = 0 | |
// Loop starting at 1 through each of the fibonacci | |
// numbers until we find the one we want | |
for i := 1; i < nth; i++ { | |
nextNumber = lastNumber + currentNumber | |
lastNumber = currentNumber | |
currentNumber = nextNumber | |
} | |
// Output the fibonacci number we want | |
fmt.Println(currentNumber) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment