Arithmetic/Integer: Difference between revisions
Content added Content deleted
Line 249: | Line 249: | ||
=={{header|Groovy}}== |
=={{header|Groovy}}== |
||
<lang groovy>def arithmetic = { a, b -> |
|||
println """ |
|||
a + b = ${a} + ${b} = ${a + b} |
|||
a - b = ${a} - ${b} = ${a - b} |
|||
a * b = ${a} * ${b} = ${a * b} |
|||
a / b = ${a} / ${b} = ${a / b} !!! |
|||
(int)(a / b) = (int)(${a} / ${b}) = ${(int)(a / b)} !!! |
|||
a % b = ${a} % ${b} = ${a % b} |
|||
Exponentiation is also a base arithmetic operation in Groovy, so: |
|||
a ** b = ${a} ** ${b} = ${a ** b} |
|||
""" |
|||
}</lang> |
|||
Program: |
|||
<lang groovy>arithmetic(5,3)</lang> |
|||
Output: |
|||
<pre>a + b = 5 + 3 = 8 |
|||
a - b = 5 - 3 = 2 |
|||
a * b = 5 * 3 = 15 |
|||
a / b = 5 / 3 = 1.6666666667 !!! |
|||
(int)(a / b) = (int)(5 / 3) = 1 !!! |
|||
a % b = 5 % 3 = 2 |
|||
Exponentiation is also a base arithmetic operation in Groovy, so: |
|||
a ** b = 5 ** 3 = 125</pre> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |