Arithmetic/Integer: Difference between revisions

Content added Content deleted
(Updated D code to D2)
(Added Frink.)
Line 658: Line 658:
4 % 3 = 1
4 % 3 = 1
</lang>
</lang>


=={{header|Frink}}==
This demonstrates normal division (which produces rational numbers when possible), <CODE>div</CODE>, and <CODE>mod</CODE>. <CODE>mod</CODE> uses the sign of the second number. All operators automatically produce big integers or exact rational numbers when necessary.
<lang frink>
[a,b] = input["Enter numbers",["a","b"]]
ops=["+", "-", "*", "/", "div" ,"mod" ,"^"]
for op = ops
{
str = "$a $op $b"
println["$str = " + eval[str]]
}
</lang>

Output is:
<lang frink>
10 + 20 = 30
10 - 20 = -10
10 * 20 = 200
10 / 20 = 1/2 (exactly 0.5)
10 div 20 = 0
10 mod 20 = 10
10 ^ 20 = 100000000000000000000
</lang>

=={{header|GAP}}==
=={{header|GAP}}==
<lang gap>run := function()
<lang gap>run := function()