add two numbers in go

To add two numbers in Go, you can create two variables and assign values to them, then use the + arithmetic operator to add them together. Here's an example code snippet:

main.go
package main

import "fmt"

func main() {
    var num1 int = 5
    var num2 int = 10
    var sum int = num1 + num2
    fmt.Println("The sum of", num1, "and", num2, "is", sum)
}
177 chars
11 lines

In this example, we create two variables num1 and num2, and assign the values 5 and 10 to them, respectively. We then create another variable sum and use the + operator to add num1 and num2 together, assigning the result to sum. Finally, we use the Println() function from the fmt package to print out the sum to the console. Running this code will output:

main.go
The sum of 5 and 10 is 15
26 chars
2 lines

gistlibby LogSnag