Go Language Tutorial
Basic arithmetic operations such as addition (+), subtraction (-), multiplication (*), and division (/) are supported in Go programming.
Below Go code is used to illustrate the basic arithmetic operations.
package main import "fmt" func main() { // declare variables var a, b, c int // assign values a = 10 b = 4 // arithmetic operations // addition of a and b c = a + b fmt. Printf("%d + %d = %d\n", a, b, c) // subtraction of a and b c = a - b fmt. Printf("%d - %d: %d\n", a, b, c) // multiplication of a and b c = a * b fmt. Printf("%d * %d: %d\n", a, b, c) // division of a and b d := float32(a) / float32(b) fmt. Printf("%d + %d: %.2f\n", a, b, d) }Output:
$ go build arithmetic-operations.go $ ./arithmetic-operations 10 + 4 = 14 10 - 4: 6 10 * 4: 40 10 + 4: 2.50« Previous Next »