Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Arithmetic-Integer/Go/arithmetic-integer-1.go
Normal file
15
Task/Arithmetic-Integer/Go/arithmetic-integer-1.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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
|
||||
}
|
||||
29
Task/Arithmetic-Integer/Go/arithmetic-integer-2.go
Normal file
29
Task/Arithmetic-Integer/Go/arithmetic-integer-2.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue