GO Program to print different types of constants

How to display different types of constants

Here we are explaining how to display different types of constants in the Go program. We can use the built-in function fmt.println() to print anything. This function is defined under the fmt package and it helps to write standard output. In order to use these functions, we need to import the “fmt” package.

 

How to display different types of constants in the GO Program

We are using fmt.println() function for printing the string to the output screen. Here we are showing how to print different types of constants in the Go language. The header file math must be import for the mathematical functions. Here st is a string constant and also n,d indicates the constants. Given below are the steps which are used in the Go program. 

ALGORITHM

STEP 1: Import the package fmt, math

STEP 2: Initialise string constant st with value "example"

STEP 3: Start function main()

STEP 4: Print string constant st using fmt.println()

STEP 5: Initialise constants n,d

STEP 6: Print d, int64(d), Sin(n) using fmt.println()

 

GO Source Code

                                          package main

import (
    "fmt"
    "math"
)

const st string = "example"

func main() {
    fmt.Println(st)
    const n = 500000000
    const d = 3e20 / n
    fmt.Println(d)
    fmt.Println(int64(d))
    fmt.Println(math.Sin(n))
}
                                      

OUTPUT

example
6e+11
600000000000
-0.28470407323754404