add two numbers in Go
Code snippet on how to add two numbers in Go
package main
import "fmt"
func main() {
num1 := 5
num2 := 3
result := num1 + num2
fmt.Println(result)
}
This code is written in the Go language. It starts off by declaring the ‘package main’ which tells the compiler that this is the main executable. The ‘import’ statement is used to import the ‘fmt’ package, which provides functions for formatting input and output. The ‘func main’ is the main function of the program. Inside this function, two variables ‘num1’ and ‘num2’ are initialized with the values 5 and 3, respectively. Finally, a new variable called ‘result’ is declared which stores the sum of num1 and num2. Finally, the ‘fmt.Println’ statement is used to output the value stored in ‘result’.