程序虽然写出来了,但是不知道如何用一个大数(例如100位的大数)去初始化一个大数变量,比较遗憾!


Go语言程序:

// bigint project main.go
package main

import (
	"fmt"
	"math"
	"math/big"
)

func main() {
	// Here are some calculations with bigInts:
	im := big.NewInt(math.MaxInt64)
	in := im
	io := big.NewInt(1956)
	ip := big.NewInt(1)
	ip.Mul(im, in).Add(ip, im).Div(ip, io)
	fmt.Printf("Big Int: %v\n", ip)
	iq := big.NewInt(10000)
	ip.Mod(ip, iq)
	fmt.Printf("Big Int: %v\n", ip)
}

程序运行结果:

Big Int: 43492122561469640008497075573153004
Big Int: 3004


程序说明:

1.math包中包含有各种功能函数,包括最大的整数math.MaxInt64

2.math/big包可以用于大整数计算

3.大整数可以使用"%v"格式输出


参考链接:

1.Ubuntu安装Go语言环境

2.Ubuntu构筑LiteIDE的Go语言开发环境





相关文章:

  • 2021-08-29
  • 2022-01-03
  • 2022-12-23
  • 2021-09-26
  • 2021-12-28
猜你喜欢
  • 2021-08-04
  • 2021-11-01
  • 2021-06-25
  • 2021-12-05
相关资源
相似解决方案