package main import ( "fmt" "math/big" ) func main() { x := big.NewInt(123456789) y := big.NewInt(987654321) z := new(big.Int).Add(x, y) fmt.Println(z) }
package main import ( "fmt" "math/big" ) func main() { numbers := []*big.Int{ big.NewInt(12345), big.NewInt(54321), big.NewInt(67890), big.NewInt(98765), } sum := big.NewInt(0) for _, n := range numbers { sum = sum.Add(sum, n) } fmt.Println(sum) }In this example, we have an array of big integers "numbers" and we want to add them all together. We create a big integer "sum" and initialize it to 0. We then loop through the "numbers" array and use the "Add" function to add each element of the array to the "sum" variable. Finally, we print the result to the console. In conclusion, the "math/big" package in Go is a powerful and essential library for dealing with big integers in Go. It provides many useful functions, such as the "Add" function, which makes working with big numbers much easier.