GO Program to Generate Fibonacci Sequence Up to a Certain Number
Example to generate the Fibonacci sequence of first n numbers (entered by the user) using for loop and if condition
Example
//GOLANG Program to Generate Fibonacci Sequence Up to a Certain Number
package main
import "fmt"
func main(){
var n int
t1:=0
t2:=1
nextTerm:=0
fmt.Print("Enter the number of terms : ")
fmt.Scan(&n)
fmt.Print("Fibonacci Series :")
for i:=1;i<=n;i++ {
if(i==1){
fmt.Print(" ",t1)
continue
}
if(i==2){
fmt.Print(" ",t2)
continue
}
nextTerm = t1 + t2
t1=t2
t2=nextTerm
fmt.Print(" ",nextTerm)
}
}
Most Helpful This Week
GO language program with example of Sort Functions for integer, strings and float64 data type
GO Program to Check Whether a Number is Palindrome or Not
How to use struct that is imported from another package?
GO language program with an example of Hash Table
GO Program to Find the Largest Number Among Three Numbers
GO language program with example of Array Reverse Sort Functions for integer and strings
GO Program to Generate Multiplication Table
Program in Golang to print Pyramid of Numbers
GO Program to find area and circumference of circle
Program in Go language to Calculate Average Using Arrays