===int=== package main import "fmt" func main() { var a, b int fmt.Print("enter two integers: ") fmt.Scanln(&a, &b) fmt.Printf("%d + %d = %d\n", a, b, a+b) fmt.Printf("%d - %d = %d\n", a, b, a-b) fmt.Printf("%d * %d = %d\n", a, b, a*b) fmt.Printf("%d / %d = %d\n", a, b, a/b) // truncates towards 0 fmt.Printf("%d %% %d = %d\n", a, b, a%b) // same sign as first operand // no exponentiation operator } {{out|Example run}} enter two integers: -5 3 -5 + 3 = -2 -5 - 3 = -8 -5 * 3 = -15 -5 / 3 = -1 -5 % 3 = -2 ===big.Int=== package main import ( "fmt" "math/big" ) func main() { var a, b, c big.Int fmt.Print("enter two integers: ") fmt.Scan(&a, &b) fmt.Printf("%d + %d = %d\n", &a, &b, c.Add(&a, &b)) fmt.Printf("%d - %d = %d\n", &a, &b, c.Sub(&a, &b)) fmt.Printf("%d * %d = %d\n", &a, &b, c.Mul(&a, &b)) // Quo, Rem functions work like Go operators on int: // quo truncates toward 0, // and a non-zero rem has the same sign as the first operand. fmt.Printf("%d quo %d = %d\n", &a, &b, c.Quo(&a, &b)) fmt.Printf("%d rem %d = %d\n", &a, &b, c.Rem(&a, &b)) // Div, Mod functions do Euclidean division: // the result m = a mod b is always non-negative, // and for d = a div b, the results d and m give d*y + m = x. fmt.Printf("%d div %d = %d\n", &a, &b, c.Div(&a, &b)) fmt.Printf("%d mod %d = %d\n", &a, &b, c.Mod(&a, &b)) // as with int, no exponentiation operator } {{out|Example run}} enter two integers: -5 3 -5 + 3 = -2 -5 - 3 = -8 -5 * 3 = -15 -5 quo 3 = -1 -5 rem 3 = -2 -5 div 3 = -2 -5 mod 3 = 1