subtract two numbers in go

Here's a sample code to perform subtraction of two numbers in Go:

main.go
package main

import "fmt"

func main() {
    var num1, num2, result int

    fmt.Print("Enter first number: ")
    fmt.Scanln(&num1)

    fmt.Print("Enter second number: ")
    fmt.Scanln(&num2)

    result = num1 - num2

    fmt.Printf("%d - %d = %d", num1, num2, result)
}
276 chars
18 lines

In this code, we define three variables num1, num2, and result. We then use the fmt.Scanln() function to read in the values for num1 and num2. We then perform the subtraction operation using the - operator and store the result in the result variable. Finally, we print the result in the desired format using fmt.Printf().

related categories

gistlibby LogSnag