Sha256: 80d17e4466d2ae7ca86b0fa227bb0121f95f7206b3b3437663a1d11ff8286261

Contents?: true

Size: 596 Bytes

Versions: 10

Compression:

Stored size: 596 Bytes

Contents

import parseopt, strutils
 
var 
  opt: OptParser = initOptParser()
  str = opt.cmdLineRest.split
  a: int = 0
  b: int = 0
 
try:
  a = parseInt(str[0])
  b = parseInt(str[1])
except ValueError:
  quit("Invalid params. Two integers are expected.")
 
 
echo("a      : " & $a)
echo("b      : " & $b)
echo("a + b  : " & $(a+b))
echo("a - b  : " & $(a-b))
echo("a * b  : " & $(a*b))
echo("a div b: " & $(a div b)) # div rounds towards zero
echo("a mod b: " & $(a mod b)) # sign(a mod b)==sign(a) if sign(a)!=sign(b)
echo("a ^ b  : " & $(a ^ b))

Execute: Aritmint 4 5

Version data entries

10 entries across 7 versions & 1 rubygems

Version Path
zettacode-0.1.7 files.zettacode/arithmetic.integer/nim.txt
zettacode-0.1.6 files.zettacode/arithmetic.integer/nim.txt
zettacode-0.1.6 files.zettacode2/arithmetic.integer/nim.txt
zettacode-0.1.5 files.zettacode/arithmetic.integer/nim.txt
zettacode-0.1.5 files.zettacode2/arithmetic.integer/nim.txt
zettacode-0.1.4 files.zettacode/arithmetic.integer/nim.txt
zettacode-0.1.4 files.zettacode2/arithmetic.integer/nim.txt
zettacode-0.1.3 files.zettacode/arithmetic.integer/nim.txt
zettacode-0.1.2 files.zettacode/arithmetic.integer/nim.txt
zettacode-0.1.1 zettacode.files/arithmetic.integer/nim.txt