The source code to print all months using predefined constants is given below. The given program is compiled and executed successfully.
// Golang program to print all months
// using predefined constants
package main
import "fmt"
import "time"
func main() {
fmt.Println(time.January)
fmt.Println(time.February)
fmt.Println(time.March)
fmt.Println(time.April)
fmt.Println(time.May)
fmt.Println(time.June)
fmt.Println(time.July)
fmt.Println(time.August)
fmt.Println(time.September)
fmt.Println(time.October)
fmt.Println(time.November)
fmt.Println(time.December)
}
Output:
January
February
March
April
May
June
July
August
September
October
November
December
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt and time packages to use time and fmt related functions.
In the main() function, we used predefined constants of time structure to get the name of months. After that, we printed the name of months on the console screen.
Program/Source Code:
The source code to print all months using predefined constants is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt and time packages to use time and fmt related functions.
In the main() function, we used predefined constants of time structure to get the name of months. After that, we printed the name of months on the console screen.
need an explanation for this answer? contact us directly to get an explanation for this answer