package main import ( "fmt" "math/big" ) func main() { r1 := big.NewRat(1, 2) r2 := big.NewRat(3, 4) // addition r3 := new(big.Rat).Add(r1, r2) fmt.Println(r3) // Output: 5/4 }
package main import ( "fmt" "math/big" ) func main() { r1 := big.NewRat(1, 3) r2 := big.NewRat(3, 7) // multiplication r3 := new(big.Rat).Mul(r1, r2) fmt.Println(r3) // Output: 1/7 }In this example, we create two rational numbers `r1` and `r2` using `big.NewRat()`. We then multiply them together using `new(big.Rat).Mul()`. The result is a new rational number `r3`, which is printed to the console. Both examples use the `math/big` package library for arbitrary-precision arithmetic.